Skip to content
Advertisement

Automatic data wrangling on Pandas with multiple dataframes using lists and loops

for professional purposes I need to produce some reports that includes new entries every week. I have 16 dataframes having same column names (df names are week1, week2… week16).

I created a list of the dataframes and then a loop. I wanted to test rename of column with index = 1 and I did not succeed.

JavaScript

I am forced to manually change every column name because I can’t set up the loop. Besides this is only one of the columns.

How can I make sure I can call all dataframes in a loop?

I have tried also the suggestions in this thread but somehow it did not work to me to use the append method. Indeed, the column names aren’t edited after I run the script.

Thanks for the help!

Advertisement

Answer

Sample dataframes:

JavaScript

Try via list comprehension and rename() method:

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