python - pandas: to_numeric for multiple columns - Stack Overflow
stackoverflow.com › questions › 36814100You can use: print df.columns[5:] Index([u'2004', u'2005', u'2006', u'2007', u'2008', u'2009', u'2010', u'2011', u'2012', u'2013', u'2014'], dtype='object') for col in df.columns[5:]: df[col] = pd.to_numeric(df[col], errors='coerce') print df GeoName ComponentName IndustryId IndustryClassification \ 37926 Alabama Real GDP by state 9 213 37951 Alabama Real GDP by state 34 42 37932 Alabama Real ...