I have a list of dataframes, df1,df2 ... df6. I want to rename all columns in these dataframes in the same way. However, when I run through it with a for list, the columns are not changed.
Here is my before dataframe:
My code:
for dataframe in [exp_ch_dt1,exp_egg_dt1,exp_ff_dt1,exp_fulfam_dt1,exp_ir_dt1,exp_rr_dt1,
exp_ch_dt2,exp_egg_dt2,exp_ff_dt2,exp_fulfam_dt2,exp_ir_dt2,exp_rr_dt2]:
dataframe = dataframe.T.rename(columns={
'Television_exp':'Television',
'Radio_exp':'Radio',
'Billboards_exp':'Billboards',
'Retail: Lottery signs/posters at retail stores_exp':'Retail: Lottery signs/posters at retail stores',
'Internet/online_exp':'Internet/online',
'Newspapers_exp':'Newspapers',
'Bus shelters_exp':'Bus shelters',
'Subway_exp':'Subway',
'Commuter train_exp':'Commuter train',
'Retail: Digital screens on monitors at retail stores_exp':'Retail: Digital screens on monitors at retail stores',
'Pay phone kiosks_exp':'Pay phone kiosks',
'Movie Theaters_exp':'Movie Theaters',
'Buses_exp':'Buses',
'Live Newscasts_exp':'Live Newscasts',
'Live TV Drawings_exp':'Live TV Drawings',
'Retail: Employees at the store_exp':'Retail: Employees at the store',
'Family or friends_exp':'Family or friends',
'New York Lottery website_exp':'New York Lottery website',
'Social media (Facebook, Twitter)_exp':'Social media (Facebook, Twitter)',
'New York Lottery app_exp':'New York Lottery app',
'Retail: Retail Location_exp':'Retail: Retail Location',
'Email newsletter_exp':'Email newsletter',
'Retail: I see the new tickets when I am at the checkout_exp':'Retail: I see the new tickets when I am at the checkout',
'Other (please specify)_exp':'Other (please specify)'
}).T
And my after dataframe:
They column names are exactly the same. Can anyone tell me why df.rename isn't working?
Comment From: MarcoGorelli
Hi - please post a reproducible example, see
https://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports
for how
Also, please don't post screenshots as they're not searchable https://youtu.be/svlsnZFWWDE
Comment From: MarcoGorelli
Actually, let's try again 😄 Please open a new issue, and don't skip the template this time