Converting strings to floats in a DataFrame

前端 未结 6 859
无人及你
无人及你 2020-11-27 12:30

How to covert a DataFrame column containing strings and NaN values to floats. And there is another column whose values are strings and floats; how to convert th

6条回答
  •  广开言路
    2020-11-27 12:48

    you have to replace empty strings ('') with np.nan before converting to float. ie:

    df['a']=df.a.replace('',np.nan).astype(float)
    

提交回复
热议问题