python - In pandas dataframe handling object data type -
i'm tearing hair out bit one. i've imported 2 csv's pandas dataframes both have column called sitereference want use pd.merge join dataframes using sitereference key.
initial merged failed pd.read took different interpretations of sitereference values, in 1 instance 380500145.0 in other 380500145 both stored objects. ran regex clean columns , pd.to_numeric, resulted in 1 value of 380500145.0 , of 3.805001e+10. should both 380500145. attempted;
df['sitereference'] = df['sitereference'].astype(int).astype('str')
but got back;
valueerror: cannot convert float nan integer
how can control how pandas dealing these, preferably on import?
perharps best solution avoid pd.read
affect type of field :
df=pd.read_csv('data.csv',sep=',',dtype={'sitereference':str})
Comments
Post a Comment