0

I've a dataframe

d = {'s': '3.4E-4'}
df = pd.Dataframe(d)

I want to convert this to numeric

pd.to_numeric(df['s'], errors='coerce')

This doesn't work because of the presence of - I think.

Any suggestion on how to convert the string to numeric?

cronoik
  • 15,434
  • 3
  • 40
  • 78
Natasha
  • 1,111
  • 5
  • 28
  • 66

1 Answers1

0

It looks like the code you posted gives errors, but you can change the type to whatever you want. Numeric could be float (which is what you would need) or int:

d = {'s': '3.4E-4'}
df = pd.DataFrame(d,index=[0])
df['s'] = df['s'].astype(float)
teepee
  • 2,620
  • 2
  • 22
  • 47