I have rows in a column with strings in a pandas dataframe that look like this:
0094
-0082
How would I replace all the values in the column so that they would be formatted like this:
94
-82
CodePudding user response:
pandas
is smart enough to figure it out with a dataframe's astype
method.
So your approach would be:
df['col of interest'] = df['col of interest'].astype(int)
CodePudding user response:
I'd suggest to use pd.to_numeric
as it provides more flexibility over .astype
:
df['col'] = pd.to_numeric(df['col'])