我的数据看起来像这样
A B C
1 2 3
4 5 6
我希望在for循环中向我的dataframe添加新行(而不是循环现有的dataframe)。
for item in queryset:
if item == 'foo':
#append new row, with only column 'b' with value
df.append({'b' : item} , ignore_index=True)
但这种方法行不通。如何将新行添加到现有的dataframe中?
发布于 2019-07-02 00:29:54
附加返回数据,而不修改数据。所以你应该做:
df = df.append({'b' : item} , ignore_index=True)
https://stackoverflow.com/questions/56848263
复制相似问题