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
  • 11,101
  • 2
  • 32
  • 61
Natasha
  • 1,259
  • 3
  • 20
  • 42

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,454
  • 2
  • 18
  • 36