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'
df=pd.read_csv('.\sources\data.csv', skip_blank_lines=True, skipinitialspace=True)header = 0in yourread_csvwithnames=nameshere you're treating the existing column row as a data row, so it becomes the first row, this then converts the dtypes to be object or in factstrfor all the rows, you can prove this by tryingprint(df.loc[df['uipid']=='50096853911'])and also it seems unnecessary to pass the column names if they match the existing column rowsdf.info()