我认为您可以使用
subset创建自
list
CONT:
print df age fnlwgt capital-gain0 a 9th 51 b 9th 62 c 8th 3CONT = ['age','fnlwgt']print df[CONT] age fnlwgt0 a 9th1 b 9th2 c 8thprint df[CONT].count()age 3fnlwgt 3dtype: int64print df[['capital-gain']] capital-gain0 51 62 3
也许更好,因为
list是
dictionary,这是由创建
to_dict:
d = df[CONT].count().to_dict()print d{'age': 3, 'fnlwgt': 3}print d['age']3print d['fnlwgt']3


