How to count number of index or Null values in Pandas dataframe group -


its things seem easy bug me. trying count of number of non-null values of variables in dataframe grouped month , year. can works fine

counts_by_month=df[variable1, variable2].groupby([lambda x: x.year,lambda x: x.month]).count() 

but want know how many of values in each group nans. want count nans in each variable can calculate percentage data missing in each group. can not find function this. or maybe same end counting total items in group. nans total - 'non-null values'

i have been trying find out if can somehow count index values haven't been able so. assistance on appreciated. best wishes jason

in [279]: df out[279]:              b         c         d         e  foo       nan  1.115320 -0.528363 -0.046242 b  bar  0.991114 -1.978048 -1.204268  0.676268 c  bar  0.293008 -0.708600       nan -0.388203 d  foo  0.408837 -0.012573  1.019361  1.774965 e  foo  0.127372       nan       nan       nan  in [280]: def count_missing(frame):     return (frame.shape[0] * frame.shape[1]) - frame.count().sum()    .....:  in [281]: df.groupby('a').apply(count_missing) out[281]: bar    1 foo    4 dtype: int64 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -