The following script prints the same input variable input_df
twice at the end - before and after df_lower
has been called:
import pandas as pd
def df_lower(df):
cols = ['col_1']
df[cols] = df[cols].applymap(lambda x: x.lower())
return df
input_df = pd.DataFrame({
'col_1': ['ABC'],
'col_2': ['XYZ']
})
print(input_df)
processed_df = df_lower(input_df)
print(input_df)
The output shows that input_df
changes:
col_1 col_2
0 ABC XYZ
col_1 col_2
0 abc XYZ
Why is input_df
modified?
Why isn't it modified when full input_df
(no column indexing) is processed?
def df_lower_no_indexing(df):
df = df.applymap(lambda x: x.lower())
return df