我读过一个csv文件,其中包含8列的熊猫read_csv
。每列可能包含int/string/float值。但是我想删除那些具有字符串值的行,并返回一个只有数字值的数据框。附加csv示例。
我试图运行此下面的代码:在Python中删除具有字符串值的熊猫数据框的行3.4.1
import pandas as pd
import numpy as np
df = pd.read_csv('new200_with_errors.csv',dtype={'Geo_Level_1' : int,'Geo_Level_2' : int,'Geo_Level_3' : int,'Product_Level_1' : int,'Product_Level_2' : int,'Product_Level_3' : int,'Total_Sale' : float})
print(df)
,但我得到了以下错误:
TypeError: unorderable types: NoneType() > int()
我与Python 3.4.1运行。 这是示例csv。
Geo_L_1,Geo_L_2,Geo_L_3,Pro_L_1,Pro_L_2,Pro_L_3,Date,Sale
1, 2, 3, 129, 1, 5193316745, 1/1/2012, 9
1 ,2, 3, 129, 1, 5193316745, 1/1/2013,
1, 2, 3, 129, 1, 5193316745, , 8
1, 2, 3, 129, NA, 5193316745, 1/10/2012, 10
1, 2, 3, 129, 1, 5193316745, 1/10/2013, 4
1, 2, 3, ghj, 1, 5193316745, 1/10/2014, 6
1, 2, 3, 129, 1, 5193316745, 1/11/2012, 4
1, 2, 3, 129, 1, ghgj, 1/11/2013, 2
1, 2, 3, 129, 1, 5193316745, 1/11/2014, 6
1, 2, 3, 129, 1, 5193316745, 1/12/2012, ghgj
1, 2, 3, 129, 1, 5193316745, 1/12/2013, 5
我只计算5列。 Geo_Level_1..3在哪里? – fredtantini 2014-10-27 08:05:34
您必须发布完整df的原始数据,您必须在读取到熊猫之前或之后清理csv – EdChum 2014-10-27 08:17:44
样本数据在上述列中存在这些错误,这就是为什么我只给出样本数据由所有8列组成。 @fredtantini – 2014-10-27 08:50:00