ValueError: could not convert string to float: '4,6'
从csv读取时,我有
1 2 3 4 5 6 | from pandas import read_csv df = read_csv("propositio/data.csv", header=None, sep=';', decimal=',') cols = ['col1', 'col2', 'col3', 'col4'] df.columns = cols df.dropna(inplace=True) |
这是一个错误。 我想将
1 | df = df.astype(float) |
ValueError: could not convert string to float: '4,6'
我该如何解决?
使用
例如:
1 2 3 4 5 | import pandas as pd df = pd.DataFrame({"A": ['4,6',"5.6", '6,6']}) df = df["A"].str.replace(',',".").astype(float) print(df) |
输出:
1 2 3 4 | 0 4.6 1 5.6 2 6.6 Name: A, dtype: float64 |