I would like to write a function that takes multiple dataframes that have the same structure, does specific transformations and saves the transformations inplace.
Dummy dataframes
df = pd.DataFrame({"Full name" : ["John Doe","Deep Smith","Julia Carter","Kate Newton","Sandy Thompson"],
"Monthly Sales" : [25,30,35,40,45]})
df2 = pd.DataFrame({"Full name" : ["Alicia Williams","Kriten John","Jessica Adams","Isaac Newton","Whitney Gordon"],
"Monthly Sales" : [35,20,50,15,40]})
Transformative function
I don't want to return the dataframe, but rather save those transformations in place.
def tidy_dfs(dfs):
for df in dfs:
# Drop first row
df = df.iloc[1: , :]
# Replace spaces in columns
df.columns = [c.replace(' ', '_') for c in df]
# change cols to lower
df.columns = [c.lower() for c in df]
return df
saving df,df2 = tidy_dfs([df,df2])
of course won't work as we're outside the loop.
Results What would be a way to call this function and save the transformation inplace?
tidy_dfs([df,df2])