I have the below data where the column values contain $. This makes the dummies created to be of dtype unsigned integer. I am trying to replace the '$' with '' resolve the dtype issue.
INPUT
grp_m1 grp_m2 grp_m3 grp_m4
$50-$75 $50-$75 $50-$75 $50-$75
$50-$75 $50-$75 $50-$75 $50-$75
$150-$175 $150-$175 $150-$175 $150-$175
$100-$125 $100-$125 $100-$125 $100-$125
$150-$175 $125-$150 $125-$150 $125-$150
My code for replacing '$' with '':
if ('$' in str(df_column[column]) == True):
new_val = [x.strip('$') for x in df_column[column].astype('str')]
df_column.replace(column.values,values = new_val, inplace = True)
I am trying to do for a single column as of now, ideally would want to deal with all columns containing '$'. So df_column is thedataframe and and column is a list containing the column names grp_m1---grp_m4.
Result:
There is no error thrown but there are no changes in the column values.
Expected Output:
grp_m1 grp_m2 grp_m3 grp_m4
50-75 50-75 50-75 50-75
50-75 50-75 50-75 50-75
150-175 150-175 150-175 150-175
100-125 100-125 100-125 100-125
150-175 125-150 125-150 125-150
Can someone please help me with this?
I had used the solution provided :
if ('$' in str(df_column[column]) == True):
df_column.values.replace('\$', '',inplace = True, regex=True)
But there is no change in the values in the dataframe.