[当我执行df.isnull()。sum()时,我得到一列中空值的计数。但是.sum()的默认轴为None或0-应该在各列中求和。
当默认值表示跨轴求和= 0时,为什么.sum()为什么要计算列而不是行的和?
谢谢!
我看到了与您所解释的相反的行为:
Sums across the columns
In [3309]: df1.isnull().sum(1)
Out[3309]:
0 0
1 1
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 0
11 0
dtype: int64
汇总各列
In [3310]: df1.isnull().sum()
Out[3310]:
date 0
variable 1
value 0
dtype: int64
嗯。这不是我所看到的功能。让我们来看这个小例子。
import pandas as pd
import numpy as np
df = pd.DataFrame({'A':[np.nan, np.nan, 3],'B':[1,1,3]}, index =[*'abc'])
print(df)
print(df.isnull().sum())
print(df.sum())
请注意,列是大写的'A'和'B',而索引或行索引是小写。
输出:
A B
a NaN 1
b NaN 1
c 3.0 3
A 2
B 0
dtype: int64
A 3.0
B 5.0
dtype: float64
每docs:
轴:{索引(0),列(1)}要应用的功能的轴上。