我有一个来自pandas的pivot_表,它有70列25行,我用
dosage = test_df[test_df > 0][[7,8]].dropna()
哪一个产生了表格
date 2014-02-19 14:15:05 2014-03-25 13:15:26
barcode
V0HX8 0.5 0.4
V0NLH 0.4 0.3
我正在尝试创建一个列“difference”,它看起来像:
date 2014-02-19 14:15:05 2014-03-25 13:15:26 Diff
barcode
V0HX8 0.5 0.4 -0.1
V0NLH 0.4 0.3 -0.1
使用以下代码:
dosage["Diff"] = dosage["2014-03-25 13:15:26"] - dosage["2014-02-19 14:15:05"]
但是得到错误:
ValueError: Wrong number of items passed 2, placement implies 1
TypeError: an integer is required
我还尝试使用以下代码:
dosage["Diff"] = dosage[[1]] - dosage[[0]] but get the error: KeyError: 'Diff'
让我们使用
.iloc
作为索引位置:相关问题 更多 >
编程相关推荐