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?

0

1 Answer 1

3

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

df = df.append({'b' : item} , ignore_index=True)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.