2
我有〜70列的數據集,看起來像這樣:計數非空的大熊貓DF
ID_number Meeting1 Meeting2 Meeting3 Meeting4 Meeting5 Comments …
123456789 9/15/2015 1/8/2016 4/27/2016 NaN NaN text text …
987654321 9/22/2016 NaN 2/25/2017 NaN NaN text text …
456789123 10/1/2015 11/30/2015 NaN NaN NaN text text …
我想創建一個額外的列(meeting_count)具有非空值的計數對於各個ID號碼的列Meeting1-Meeting5。
通常我會使用SQL和做類似:
select
Meeting1,
Meeting2,
Meeting3,
Meeting4,
Meeting5,
(
select count(*)
from (values (Meeting1), (Meeting2), (Meeting3), (Meeting4), (Meeting5)) as v(col)
where v.col is not null
) as meeting_count
from Table
但是,如果有一個相當簡單的方法來做到這一點在Python,我寧願做。