简体   繁体   English

如何遍历数据框的列,然后在这些列中的每一列上运行 describe() 函数?

[英]How do I iterate through a dataframe's columns and then run the describe() function on each of these columns?

What I have tried so far is to iterate through the dataframe columns and then use the control variable in the df.<columnName>.describe() function, but this doesn't seem to work...到目前为止我尝试过的是遍历数据框列,然后在df.<columnName>.describe()函数中使用控制变量,但这似乎不起作用......

for (columnName, columnData) in df.iteritems():
  print('Column Name: {}'.format(columnName))
  column_stats = df.columnName.describe()

This is the output :这是输出:

attr__ return object. attr__ 返回对象。 getattribute (self, name) AttributeError: 'DataFrame' object has no attribute 'columnName' getattribute (self, name) AttributeError: 'DataFrame' 对象没有属性 'columnName'

Can someone help me with this rather trivial doubt ...有人可以帮我解决这个相当微不足道的疑问吗...

Try it:尝试一下:

for columnName, columnData in df.iteritems():
    print('Column Name: {}'.format(columnName))
    column_stats = df[columnName].describe()

df.columnName is searching for a Column Name ColumnName not the value of your variable df.columnName 正在搜索列名 ColumnName 不是变量的值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM