在Python 3.4中从DataFrame中删除NA值 [英] removing NA values from a DataFrame in Python 3.4

查看:1336
本文介绍了在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值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆