0

I'd like to loop through every DataFrame in my Python workbook and change all column names to lower case and snake case. I tried this code, with a list of the DataFrames, but keep getting an AtrributeError?

df_list = ['accounting','finance','fp_a','marketing','safety','supply_management']
for df in df_list:
    df.rename(columns=lambda col: col.replace(' ', '_').lower(), inplace=True)

AttributeError: 'str' object has no attribute 'rename'

  • is this the exact code ? since df is not DataFrame here, you are looping over just strings and rename is not function of str you will get AttributeError. you may look into https://stackoverflow.com/questions/11346283/renaming-column-names-in-pandas?rq=2 – Developer Jun 09 '23 at 20:36

0 Answers0