Is there a way to convert values like '34%' directly to int or float when using read_csv in pandas? I want '34%' to be directly read as 0.34
Using this in
read_csv
did not work:read_csv(..., dtype={'col':np.float})
After loading the csv as 'df' this also did not work with the error "invalid literal for float(): 34%"
df['col'] = df['col'].astype(float)
I ended up using this which works but is long winded:
df['col'] = df['col'].apply(lambda x: np.nan if x in ['-'] else x[:-1]).astype(float)/100