How would you optimize this code?
You can replace the symbol in dataframe without iterating yourself.

df = df.replace({'R\$': ''}, regex=True)

Then change the type of columns that can be numeric. If you don't know which are those columns, use this that will automatically change the type to numeric and ignore those that cannot be changed.

df = df.apply(pd.to_numeric, errors='ignore')

When you use replace and in general many other pandas features, it doesn't update your dataframe. It creates a new, temporary dataframe. So, you either need to assign it back to your original dataframe or use inplace=True wherever it is available, like:

df.replace({'R\$': ''}, regex=True, inplace = True)

$ is a special character in regex, so you need to escape it. That's why the backslash before it.

import pandas as pd

dic = {'feature1': 'R$ aaa bb', 'feature2': 1} 
df = pd.DataFrame(dic, index=[0,1])

print(df)

&gt;&gt;  feature1  feature2
0  R$ aaa bb         1
1  R$ aaa bb         1

df = df.replace({'R\$': ''}, regex=True)

print(df)

&gt;&gt;  feature1  feature2
0   aaa bb         1
1   aaa bb         1