Let there be several similar dataframes that an operation is to be performed on, e.g. dropping or renaming columns. One may want to do it in a loop:
this = pd.DataFrame({'text': ['Hello World']})
that = pd.DataFrame({'text': ['Hello Gurl']})
for df in [this, that]:
df = df.rename(columns={'text': 'content'})
No exception is raised, however, the dataframes remain unchanged. Why is that and how can I iterate over dataframes without having to type the same line of code dozens of times?
On other hand, operations like creating new columns do work:
for df in [this, that]:
df['content'] = df.text