pythonpandasjupyter-notebook

Price column object to int in pandas


I have a column called amount with holds values that look like this: $3,092.44 when I do dataframe.dtypes() it returns this column as an object how can i convert this column to type int?


Solution

  • in regex \D means not digit... so we can use pd.Series.str.replace

    dataframe.amount.replace('\D', '', regex=True).astype(int)
    
    0    309244
    1    309244
    Name: amount, dtype: int64