我的数据框看起来像这样
A B C
1 2 3
4 5 6
我想在forloop中添加新行到我的数据框中(不循环现有数据框)
for item in queryset:
if item == 'foo':
#append new row, with only column 'b' with value
df.append({'b' : item} , ignore_index=True)
但是这种方法不起作用。如何在现有数据框中添加新行?
答案 0 :(得分:1)
append返回一个数据框,并且不修改该数据框。所以你应该做:
df = df.append({'b' : item} , ignore_index=True)