Pandascount()定义为一种用于计算每一列或每一行的非NA单元数的方法。
DataFrame.count(axis=0, level=None, numeric_only=False)
如果指定级别,则返回Series或DataFrame的计数。
示例1:下面的示例演示 count()的工作。
import pandas as pd import numpy as np info = pd.DataFrame({"Person":["Parker", "Learnfk", "William", "John"], "Age": [27., 29, np.nan, 32] info.count()
输出
Person 5 Age 3 dtype: int64
示例2:如果要对每一行进行计数,则可以使用 axis 参数。以下代码演示了 axis 参数的工作方式。
import pandas as pd import numpy as np info = pd.DataFrame({"Person":["Parker", "Learnfk", "William", "John"], "Age": [27., 29, np.nan, 32] info.count(axis='columns')
输出
0 2 1 2 2 1 3 2 dtype: int64
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)