0

My dataframe looks like this

A    B    C
1    2    3
4    5    6

I want to add new rows to my dataframe in a forloop (not looping the existing dataframe)

for item in queryset:
    if item == 'foo':
        #append new row, with only column 'b' with value
        df.append({'b' : item} , ignore_index=True)

But this method does not work. How could I add a new row to my existing dataframe?

Tomas Jacobsen
  • 2,368
  • 6
  • 37
  • 81

1 Answers1

3

append return a dataframe and does not modify the dataframe. So you should do :

df = df.append({'b' : item} , ignore_index=True)
Simon Delecourt
  • 1,519
  • 8
  • 13