这是我的csv文件:
uipid,shid,pass,camera,pointheight,pointxpos,PointZPos,deffound,HighestHeight,XPosition,ZPosition,RLevel,Rejected,MixedP
50096853911,6345214,1,SXuXeXCamera,218,12600,82570,no,-1,-1,-1,880,no,498
49876879038,6391743,1,SZuZeZCamera,313,210400,187807,no,-1,-1,-1,880,no,388
这是我的代码:
df=pd.read_csv('.\sources\data.csv', delimiter=',', names=['uipid','shid','pass','camera','pointheight','pointxpos','PointZPos','deffound','HighestHeight', 'XPosition','ZPosition','RLevel','Rejected','MixedP'], skip_blank_lines=True, skipinitialspace=True, engine='python')
当我选择一列print(df.loc[(df['uipid']==50096853911))
时,我得到一个空的df。
清空DataFrame 列[uipid,SHID,传球,照相机,pointheight,pointxpos,PointZPos,deffound,HighestHeight,x向位置,z向位置,RLevel,拒绝,MixedP] 指数:[]
当我在dtype
中设置pd.read_csv
时:
df=pd.read_csv('.\sources\data.csv', delimiter=',' ,dtype={'uipid':int, 'shid': int, 'pass':int, 'camera':str, 'pointheight':int, 'pointxpos':int , 'PointZPos':int, 'deffound':str, 'HighestHeight':int, 'XPosition':int,'ZPosition':int, 'RLevel':int, 'Rejected':str, 'MixedP':int}, names=['uipid','shid','pass','camera','pointheight','pointxpos','PointZPos','deffound','HighestHeight', 'XPosition','ZPosition','RLevel','Rejected','MixedP'], skip_blank_lines=True, index_col=False, encoding="utf-8", skipinitialspace=True)
我收到此错误:
TypeError:无法将数组从dtype('O')转换为dtype('int32') 根据规则'安全'
ValueError:基数为10的int()的文字无效:'uipid'
答案 0 :(得分:1)
尝试将header = 0
放入您的第二个read_csv
示例中,并告知我们是否有效。
答案 1 :(得分:0)
尝试一下:
df_trail=pd.read_csv('/content/New Text Document.txt',
delimiter=',',
names=['uipid', 'shid', 'pass', 'camera', 'pointheight', 'pointxpos', 'PointZPos', 'deffound', 'HighestHeight', 'XPosition', 'ZPosition', 'RLevel', 'Rejected', 'MixedP'],
skip_blank_lines=True, skipinitialspace=True, engine='python',header=0)