我用下面的df工作:大熊猫:to_numeric多个列
c.sort_values('2005', ascending=False).head(3)
GeoName ComponentName IndustryId IndustryClassification Description 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014
37926 Alabama Real GDP by state 9 213 Support activities for mining 99 98 117 117 115 87 96 95 103 102 (NA)
37951 Alabama Real GDP by state 34 42 Wholesale trade 9898 10613 10952 11034 11075 9722 9765 9703 9600 9884 10199
37932 Alabama Real GDP by state 15 327 Nonmetallic mineral products manufacturing 980 968 940 1084 861 724 714 701 589 641 (NA)
我要强制数字上的所有年:
c['2014'] = pd.to_numeric(c['2014'], errors='coerce')
有一种简单的方法来做到这个还是我必须全部输入?
感谢MaxU,对于你的答案:) –
@MichaelPerdue中,很高兴帮助:) – MaxU
为了完整:你也可以做转换初始化数据帧例如,当上了飞:pd.DataFrame(DataList控件,D型=浮动),它会将所有字段转换为可能的字段(并保持其他字段不变) – poppie