Search and replace dots and commas in pandas dataframe

The best is use if possible parameters in read_csv:

df = pd.read_csv(file, thousands=".", decimal=",")

If not possible, then replace should help:

df['col2'] = (df['col2'].replace('\.','', regex=True)
                        .replace(',','.', regex=True)
                        .astype(float))

Leave a Comment