1

My dataframe (df_UP) looks like this:

 Total_trends #up #down #flat 0.05 811 326 310 175 

I am using a jupyter notebook, when I try to append a row with the following code:

`d = {'Total_trends': [total.time], '#up': [good_trigger.time], '#down': [bad_trigger.time], '#flat': [flat.time]} df_UP.append(d, ignore_index=True)` 

It works the first time:

Total_trends #up #down #flat 0 811 326 310 175 1 [811] [326] [310] [175] 

But when I run again the cell with other values in d, it just overwrites the existing data at row 1 with the new one, any idea why? Thanks!

2
  • For me it working perfectly, maybe need df_UP = df_UP.append(pd.DataFrame(d), ignore_index=True) ? Commented Feb 28, 2019 at 11:12
  • @jezrael, yup the following: df_UP = df_UP.append(pd.DataFrame(d), ignore_index=True) works! you can add it as answer, I will validate it! thanks! Commented Feb 28, 2019 at 11:15

1 Answer 1

1

You can convert dictionary to DataFrame and assign back:

d = {'Total_trends': [10], '#up': [20], '#down': [3], '#flat': [0]} df_UP = df_UP.append(pd.DataFrame(d), ignore_index=True) print (df_UP) Total_trends #up #down #flat 0 811 326 310 175 1 10 20 3 0 d = {'Total_trends': [160], '#up': [270], '#down': [63], '#flat': [30]} df_UP = df_UP.append(pd.DataFrame(d), ignore_index=True) print (df_UP) Total_trends #up #down #flat 0 811 326 310 175 1 10 20 3 0 2 160 270 63 30 
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.