在 python pandas 中读取缺失值的文件 [英] reading file with missing values in python pandas
问题描述
我尝试使用 pandas.read_csv 读取缺少值的 .txt.我的数据格式为:
I try to read .txt with missing values using pandas.read_csv. My data is of the format:
10/08/2012,12:10:10,name1,0.81,4.02,50;18.5701400N,4;07.7693770E,7.92,10.50,0.0106,4.30,0.0301
10/08/2012,12:10:11,name2,,,,,10.87,1.40,0.0099,9.70,0.0686
具有数千个具有相同点名称、gps 位置和其他读数的样本.我使用代码:
with thousands of samples with same name of the point, gps position, and other readings. I use a code:
myData = read_csv('~/data.txt', sep=',', na_values='')
代码错误,因为 na_values 没有给出 NaN 或其他指标.列应该具有相同的大小,但我以不同的长度完成.
The code is wrong as na_values does not gives NaN or other indicator. Columns should have the same size but I finish with different length.
我不知道在 na_values 之后到底应该输入什么(尝试了所有不同的东西).谢谢
I don't know what exactly should be typed in after na_values (did try all different things). Thanks
推荐答案
参数 na_values
必须是list like"(参见这个 答案).
The parameter na_values
must be "list like" (see this answer).
一个字符串是类似列表",所以:
A string is "list like" so:
na_values='abc' # would transform the letters 'a', 'b' and 'c' each into `nan`
# is equivalent to
na_values=['a','b','c']
同样:
na_values=''
# is equivalent to
na_values=[] # and this is not what you want!
这意味着您需要使用na_values=['']
.
这篇关于在 python pandas 中读取缺失值的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!