<p>您可以使用<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.ix.html" rel="nofollow">^{<cd1>}</a>选择列,然后使用<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.apply.html" rel="nofollow">^{<cd2>}</a><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_numeric.html" rel="nofollow">^{<cd3>}</a>:</p>
<pre><code>import pandas as pd
df = pd.DataFrame({1:['1','2','3'],
2:[4,5,6],
3:[7,8,9],
4:['1','3','5'],
5:[5,3,6],
6:['7','4','3']})
print (df)
1 2 3 4 5 6
0 1 4 7 1 5 7
1 2 5 8 3 3 4
2 3 6 9 5 6 3
print (df.dtypes)
1 object
2 int64
3 int64
4 object
5 int64
6 object
dtype: object
print (df.columns)
Int64Index([1, 2, 3, 4, 5, 6], dtype='int64')
</code></pre>
^{pr2}$
<p>如果列是<code>strings</code>,则不是<code>int</code>(但看起来像<code>int</code>)将<code>''</code>添加到<code>list</code><code>cols</code>中的数字:</p>
<pre><code>import pandas as pd
df = pd.DataFrame({'1':['1','2','3'],
'2':[4,5,6],
'3':[7,8,9],
'4':['1','3','5'],
'5':[5,3,6],
'6':['7','4','3']})
#print (df)
#print (df.dtypes)
print (df.columns)
Index(['1', '2', '3', '4', '5', '6'], dtype='object')
#add `''`
cols = ['1','4','6']
#1. ix: supports mixed integer and label based access
df.ix[:, cols] = df.ix[:, cols].apply(pd.to_numeric)
#2. loc: only label based access
# df.loc[:, cols] = df.loc[:, cols].apply(pd.to_numeric)
#3. iloc: for index based access
# cols = [i for i in range(len(df.columns))]
# df.iloc[:, cols].apply(pd.to_numeric)
print (df)
1 2 3 4 5 6
0 1 4 7 1 5 7
1 2 5 8 3 3 4
2 3 6 9 5 6 3
print (df.dtypes)
1 int64
2 int64
3 int64
4 int64
5 int64
6 int64
dtype: object
</code></pre>