在Python 3.4中从DataFrame中删除NA值

编程入门 行业动态 更新时间:2024-10-27 17:10:05
本文介绍了在Python 3.4中从DataFrame中删除NA值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 import pandas as pd import statistics df=print(pd.read_csv('001.csv',keep_default_na=False, na_values=[""])) print(df)

我正在使用此代码创建没有NA值的数据框.我有几个CSV文件,我想计算其中一列的均值-硫酸盐.此列包含许多"NA"值,我尝试将其排除在外.即使使用了上面的代码,也不会从数据帧中排除"NA". 请提出建议.

I am using this code to create a data frame which has no NA values. I have couple of CSV files and I want to calculate Mean of one of the columns - sulfate. This column has many 'NA' values, which I am trying to exclude. Even after using the above code, 'NA's aren't excluded from the data frame. Please suggest.

推荐答案

我认为您应该按原样导入.csv文件,然后处理数据框. 然后,您可以使用以下任何一种方法.

I think you should import the .csv file as it is and then manipulate the data frame. Then, you can use any of the methods below.

foo[foo.notnull()]

foo.dropna()

更多推荐

在Python 3.4中从DataFrame中删除NA值

本文发布于:2023-11-23 11:06:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621228.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Python   NA   DataFrame

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!