python - Pandas: substitute commas for points in a column -


i have column of values csv-file contain commas instead of points. code below want turn these points, not work.

there no error message, code runs , if call column betrag() (german: absolute value) datafram umsatz, display no change. commas still in place.

def removecom(value): value=value.replace(',','.')  umsatz['betrag()']=umsatz['betrag()'].apply(lambda value: removecom(value))  umsatz['betrag()'] 

for instance turn 7,99 7.99

the reason see no change because removecom returns nothing. should return value function this:

def removecom(value):     return value.replace(',','.') 

however, better method recommend using df.str.replace:

umsatz['betrag()'] = umsatz['betrag()'].str.replace(',', '.') 

demo:

in [750]: df out[750]:        col1 0  foo,bar 1  abc,def  in [751]: df['col1'] = df.col1.str.replace(',', '.')  in [752]: df out[752]:        col1 0  foo.bar 1  abc.def 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -