简体   繁体   中英

pandas.read_csv returns empty dataframe

here is my csv file:

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

Here is my code:

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')

and when I select a column print(df.loc[(df['uipid']==50096853911)) I get an empty df.

Empty DataFrame Columns[uipid,shid,pass,camera,pointheight,pointxpos,PointZPos,deffound,HighestHeight,XPosition,ZPosition,RLevel,Rejected,MixedP] Index: []

And when i set the dtype in 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)

I get this error:

TypeError: Cannot cast array from dtype('O') to dtype('int32') according to the rule 'safe'

ValueError: invalid literal for int() with base 10: 'uipid'

尝试将header = 0放在您的第二个read_csv示例中,并让我们知道它是否有效。

Try this:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM