I have a list of dataframes such that
df_lst = [df1, df2]
I also created a function which removes the rows with '0' in the dataframe:
def dropzeros(df):
newdf = df[df['x']!=0.0]
return newdf
I tried applying this through a loop and placed an assignment variable within the loop, but the original dataframe remained unchanged even after running the loop.
for df in df_lst:
df = dropzeros(df)
I also tried using list comprehensions to go about it
df_lst = [dropzeros(df) for df in df_lst]
I know the function works since when i apply print(len(df)) before and after the command dropzeros(df) there was a drop in the len, however, may I know how might I go about this problem such that my original dataframe is altered after running the loop?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.