簡體   English   中英

查找 pandas dataframe 中非 NAN 元素的總數

[英]Finding the total number of non-NAN elements in pandas dataframe

我知道 df.count() 和 df.groupby.count(),但我只想要我的 dataframe 的特定列(比如稱為“汽車”)的非 NAN 元素的數量。

我知道 df.size[0],但這個命令不尊重非 NAN 元素的數量在不同列中可能不同的事實。

還有系列count 它也忽略了NaN 從文檔

s = pd.Series([0.0, 1.0, np.nan])
s.count()

Out[307]: 2

所以,對於柱cars

df['cars'].count()

將返回列cars的非 NaN 值的數量

我們也可以使用Series.notna + Series.sum

df.cars.notna().sum()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM