base = base["DY"].str.replace(',', '.').astype(float)
ValueError: could not convert string to float: '6.1%'
How convert string to float in pandas in only column?
base = base["DY"].str.replace(',', '.').astype(float)
ValueError: could not convert string to float: '6.1%'
How convert string to float in pandas in only column?
Consider:
import pandas as pd
df=pd.DataFrame({"col": ["4,2", "5.79", "-6,23%", "9.6%"]})
df["col2"]=df["col"].str.replace(",",".").str.replace("%", "*0.01").map(eval)
>>> df
col col2
0 4,2 4.2000
1 5.79 5.7900
2 -6,23% -0.0623
3 9.6% 0.0960
You can use something like this below:-
base = base["DY"].str.replace(',' , '.').replace('%', '').astype(float)