Python Forum
Converting Dataframe in Python from Object to Float
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Converting Dataframe in Python from Object to Float
#4
You need to get rid of the commas in the strings
df['GER30_Open_float'] = df['GER30_Open'].str.replace(',', '').astype(float)
As already mentioned if using pandas.read_csv() you can use parameter thousands=',' to get rid of the commas
df = pandas.read_csv('example.csv', thousands=',')
Reply


Messages In This Thread
RE: Converting Dataframe in Python from Object to Float - by ThomasL - Aug-28-2019, 12:00 PM
I am getting error in this code - by AnkitGupta - Jan-08-2020, 04:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  converting dataframe to int numpy array glennford49 1 2,357 Apr-04-2020, 06:15 AM
Last Post: snippsat
  Converting string the pandas dataframe chrismc 0 2,380 Jan-24-2019, 11:07 AM
Last Post: chrismc
  Converting Flattened JSON to Dataframe in Python 2.7 ManMan 1 5,306 Jul-12-2017, 06:52 PM
Last Post: ManMan
  The problem of converting string to float by using CSV file CChen 2 12,986 Jul-11-2017, 03:32 PM
Last Post: CChen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020