Jun-21-2019, 08:44 AM
You should use
pd.read_csv
for this task. This function has many parameters which define the behavior of parsing data and they know the problem with comma
or dot
as decimal sign. Also the thousands sep can and should be specified. You should read this document: https://pandas.pydata.org/pandas-docs/st...d_csv.htmlfrom textwrap import dedent from io import StringIO import pandas as pd data = """ source;rev a;1,00 b;1.000,20 c;123,45 """ csv_data = StringIO(dedent(data.strip())) # csv_data is a file-like object # just for testing df = pd.read_csv(csv_data, decimal=',', thousands='.', sep=';') print(df['rev'])
Output:0 1.00
1 1000.20
2 123.45
Name: rev, dtype: float64
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!