【发布时间】:2017-03-11 03:49:07
【问题描述】:
我在 pandas/Python 中使用 read_table 命令导入制表符分隔的文本文件。
q_data_1 = pd.read_table('data.txt', skiprows=6, dtype={'numbers': np.float64})
...但是得到
AttributeError: 'NoneType' object has no attribute 'dtype'
如果没有 dtype 参数,该列将作为“对象”dtype 导入。
我认为“数字”列缺少导致导入失败的数据。如何忽略这些值?
编辑(13 年 5 月 25 日):知道如何使用包含 (i) 时间(例如“00:03:06”)(ii) 日期(例如“2002-03-11”)的列执行此操作和百分比('32.81%')?所有这些都转换为对象。 (我编辑了 Q 以反映)(iv)带逗号的数字(例如“10,982”)以将它们转换为适当的 dtype?
【问题讨论】:
-
如果没有你指定,它不会得到这个 dtype 吗?
-
不 - 它将整个列作为对象导入
-
“数字”中有什么不是浮点数?你希望它是怎样的?
-
什么是 'AttributeError: 'NoneType' object has no attribute 'dtype' - 这是否意味着它不能将其中一个数字转换为浮点数?
-
看到这个问题:stackoverflow.com/questions/16729483/…,你应该把它读进去然后转换(因为我假设你文件中的分隔符不是逗号)