Image for the code:-
I m struggling updating the original dataframe when using a user defined function for running a task:
def filter_rows(df,col,string):
df[col] = df[col].astype(str)
df = df[~df[col].str.contains(string)]
return df
When i run the above function on df1
, it does return a trimmed down version. But that version is not updated in main df1
.
filter_rows(df1,'smoking_status','never smoked')
Meaning if i view df1
seperatly in the next cell, I still see the complete non trimmed dataset.
I've used inplace=True
where possible but I cant seem to find a way to do that here.
Need a solution that could be used in other situations aswell.
Thanks in advance. :)