I have following dataframe in pandas.
order_id no
1 1,234,450,445.00
2 1,234,450,446.00
3 1,234,450,447.00
I want to convert the no column to integer. Following is my desired dataframe.
order_id no
1 1234450445
2 1234450446
3 1234450447
When I do dtypes, it shows as float64
I tried following
df['no'] = (pd.to_numeric(df['no'].str.replace(',',''), errors='coerce'))
How can I convert this to integer in pandas?
df.no.str.replace(",", "").str[:-3].astype(int). If you are reading in the file as a csv, pandas has a thousands parameterTypeError: only integer scalar arrays can be converted to a scalar indexdf.no.str.replace(",", "").str[:-3]?df.no.str.replace(",", "").astype(float).astype(int)