Skip to content
Advertisement

Pandas append does not work (dataframe is not getting bigger)

I am currently trying to write a code that is supposed to add mulitple dataframes into one, using the append method. However, with the code I currently use, it seems that only the first dataframe is read. I have tried locating the problem by adding a len(df) to my code and it seems to that the merged dataframe lenght does not change after appending a new one. I am also using a loop that reads threw the files in a folder and this is used in order to only use the top rows for the first dataframe and then skip them when it is not the first.

In my loop I get the output:

41568

READING FILE 2

lenght of added dataframe 1044

lenght of appended dataframe: 41568

READING FILE 3

lenght of added dataframe 9138

lenght of appended dataframe: 41568

I expected to get the results of a combined dataframe.

The expected output is:

41568

READING FILE 2

lenght of added dataframe 1044

lenght of appended dataframe: 42612

READING FILE 3

lenght of added dataframe 9138

lenght of appended dataframe: 51750

My current code is:

JavaScript

Does anyone know how to fix this problem?

Than you in advance!

Advertisement

Answer

After appending the dataframe you need to asssign it to variable like below

merged_df = merged_df.append(testcsv)

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