I was creating this function:
def stand_col_names(*df_to_stand):
'''function that allow you to lowercase dataframes columns'''
df_to_stand.columns = df_to_stand.columns.str.lower()
return df_to_stand
As you can see my goal is to pass multiple dataframes simultaneously in order to convert columns names. Something like this:
df1,df2,df3,df4 = stand_col_names(df1,df2,df3,df4)
I dont' wanna a function that take only one argument and therefore write four rows, one for each dataframe.
When I run it I get the following error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-20-c4c8e2ccc0f3> in <module>
----> 1 df_target_pm,df_target_sp=stand_col_names(df_target_pm,df_target_sp)
<ipython-input-18-65eb087bc145> in stand_col_names(*df_to_stand)
1 def stand_col_names(*df_to_stand):
2 '''function that allow you to lowercase dataframes columns'''
----> 3 df_to_stand.columns = df_to_stand.columns.str.lower()
4 return df_to_stand
AttributeError: 'tuple' object has no attribute 'columns'
Could you help me please?
*is better suited when you want to do an operation that could depend on a variable number of things. For instance, imagine you wanted to sum together a variable number of arrays. Here, though you want to act on a variable number of DataFrames the result only ever depends on the individual DataFrames themselves. IMO, the function should accept and return a single DataFrame and the loop should exist outside. i.efor df in dfs: df = stand_col_names(df)