我正在处理数据框
data = {'country': ['Belgium', 'France', 'Germany', 'Netherlands', 'United Kingdom'],
'population': [11.3, 64.3, 81.3, 16.9, 64.9],
'area': [30510, 671308, 357050, 41526, 244820],
'capital': ['Brussels', 'Paris', 'Berlin', 'Amsterdam', 'London']}
countries = DataFrame(数据,索引=列表(' pqrst'))
现在我想将函数标准化仅应用于标准化数值列。我已将此函数定义为
def standardizing(s):
t=s.apply(lambda x: (x-s.mean())/s.std())
print t,'\n'
print "New standardized mean ",t.mean()
print "New standardized deviation ",t.std()
standardizing
答案 0 :(得分:0)
使用select_dtypes函数,然后遍历该数据框的列。
numeric_data = countries.select_dtypes(include=['number'])
for col_name in numeric_data:
standardizing(numeric_data[col_name])