-1
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?

DYZ
  • 55,249
  • 10
  • 64
  • 93

2 Answers2

0

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
halfer
  • 19,824
  • 17
  • 99
  • 186
Grzegorz Skibinski
  • 12,624
  • 2
  • 11
  • 34
0

You can use something like this below:-

base = base["DY"].str.replace(',' , '.').replace('%', '').astype(float) 
zenwraight
  • 2,002
  • 1
  • 10
  • 14
Wahib Mzali
  • 120
  • 5