简体   繁体   English

从列表中的 pandas 数据帧中删除 NaN 值

[英]Remove NaN values from pandas dataframes inside a list

I have a number of dataframes inside a list.我在列表中有许多数据框。 I am trying to remove NaN values.我正在尝试删除 NaN 值。 I tried to do it in a for loop:我试图在 for 循环中做到这一点:

for i in list_of_dataframes:
    i.dropna()

it didn't work but python didnt return an error neither.它没有用,但 python 也没有返回错误。 If I apply the code如果我应用代码

list_of_dataframes[0] = list_of_dataframes[0].dropna()

to a each dataframe individually it works, but i have too many of them.每个 dataframe 单独工作,但我有太多。 There must be a way which I just can't figure out.一定有一种我无法弄清楚的方法。 What are the possible solutions?有哪些可能的解决方案?

Thanks a lot非常感谢

You didn't assign the new DataFrames with the dropped values to anything, so there was no effect.您没有将带有删除值的新 DataFrame 分配给任何东西,因此没有任何效果。

Try this:尝试这个:

for i in range(len(list_of_dataframes)):
    list_of_dataframes[i] = list_of_dataframes[i].dropna()

Or, more conveniently:或者,更方便的是:

for df in list_of_dataframes:
    df.dropna(inplace=True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM