1

I have a few pandas dataframes df_all_ticket_type, df_all_category, df_all_sub_category1 for which same function has to be called for some processing. The names of DFs are in a List.

list_df_names = ['df_all_ticket_type', 'df_all_category', 'df_all_sub_category1'] 

I want to call a function to clean these DFs using the List.

for df_name in list_df_names:
    clean_df(df_name)

df_name takes values of df_all_ticket_type, df_all_category, df_all_sub_category1 for every iteration. I don't want to pass the value but the actual DF to the function. Is there a way I can achieve this?

Main
  • 150
  • 1
  • 10

1 Answers1

0

Try using the locals() function (link to similar question)

for df_name in list_df_names:
    clean_df(locals()[df_name])
Paul Wildenhain
  • 1,321
  • 10
  • 12