我试图动态地附加到数据帧,但是在df.loc[count] = pandas.DataFrame(amounts).T
行中得到错误ValueError: Incompatible Indexer with Dataframe
。
df = pandas.DataFrame(index=numpy.arange(0, 1), columns=required_indices_of_series)
#This just creates a dataframe with the right columns, but with values I need to modify, which I aim to do below.
print('1', df)
count = 0
for bond in bonds:
#Some stuff here to get the Series Object `amounts` which is irrelevant.
print('2', pandas.DataFrame(amounts).T)
df.loc[count] = pandas.DataFrame(amounts).T
count += 1
print('1', df)
返回:
1983-05-15 1983-11-15 1984-05-15 1984-11-15
NaN NaN NaN NaN
print('2', pandas.DataFrame(amounts).T)
返回:
1983-05-15 1983-11-15 1984-05-15 1984-11-15
1 1 1 101
您这样做是错误的,您试图将一个数据帧分配给另一个数据帧中的一行。
您需要在右侧使用
pandas.DataFrame(amounts).T.loc[<columnName>]
。示例-
示例/演示-
相关问题 更多 >
编程相关推荐