pandas: to_numeric for multiple columns

后端 未结 5 1791
刺人心
刺人心 2020-11-27 03:47

I\'m working with the following df:

c.sort_values(\'2005\', ascending=False).head(3)
      GeoName ComponentName     IndustryId IndustryClassification Descri         


        
5条回答
  •  [愿得一人]
    2020-11-27 04:40

    another way is using apply, one liner:

    cols = ['col1', 'col2', 'col3']
    data[cols] = data[cols].apply(pd.to_numeric, errors='coerce', axis=1)
    

提交回复
热议问题