gpt4 book ai didi

python : How to find the count of empty cells in one column based on another column element wise?

转载 作者:行者123 更新时间:2023-12-02 00:51:34 24 4
gpt4 key购买 nike

df = pd.DataFrame({'user': ['Bob', 'Jane', 'Alice','Jane', 'Alice','Bob', 'Alice'], 
'income': [40000, np.nan, 42000, 50000, np.nan, np.nan, 30000]})

user income
0 Bob 40000.0
1 Jane NaN
2 Alice 42000.0
3 Jane 50000.0
4 Alice NaN
5 Bob NaN
6 Alice 30000.0

我想根据 df 中的“用户”列查找“收入”列中所有空值的计数?我正在尝试这样的事情: len(df[df.venue.isnull().sum()]) 但它不完整。

最佳答案

您可以使用方法value_counts():

df.loc[df['income'].isna(), 'user'].value_counts()

输出:

Jane     1
Bob 1
Alice 1
Name: user, dtype: int64

关于 python : How to find the count of empty cells in one column based on another column element wise?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59775640/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com