I have a CSV file with data reading that I want to read into Python. I get lists that contain strings like "2,5". Now doing float("2,5") does not work, because it has the wrong decimal mark.
How do I read this into Python as 2.5?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
float("2,5".replace(',', '.'))will do in most casesIf
valueis a large number and.has been used for thousands, you can:Replace all commas for points:
value.replace(",", ".")Remove all but the last point:
value.replace(".", "", value.count(".") -1)