Home>

Tell me about DataFrame type conversion.

df.loc [0, "# of TAB"]
output: '100'
df ["# of TAB"]. dtype
ouput: dtype ('O')
df ["# of TAB"]. astype (float)
ouput: could not convert string to float: '500TSE'

When the above code was executed, the object type could not be changed to the float type.
Could you tell me the reason and countermeasures?

  • Answer # 1

    df ["# of TAB"] = pd.to_numeric (df ["# of TAB"], errors = "coerce")

    The code above worked well!

Related articles