Skip to content
Advertisement

How can I append the last row on each dataframe

I am trying to use for loop to append the last row into a new dataframe. However, it only can append the last data into the new dataframe. May I know how can I fix it?

The code looks like this:

JavaScript

Advertisement

Answer

Try change the line:

JavaScript

to:

JavaScript

Your code is now resetting new_df to a new value in every iteration with the first line above. Hence, only left with the value set in the last iteration after the loop.

Also, you don’t need double square bracket [[-1]] for .iloc. Just use .iloc[-1] should bring you the last row of df.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement