简体   繁体   中英

Pandas Data frame counting how many times certain value appears in column if and only if other columns meet certain condition

I need help with pandas data frame. Trying to count all rows with a '1' value under particular column A if and only if other columns B,C,D,E,F,G are NOT blank. Any ideas?

Assuming you have a pandas data frame df with columns ABCDEFG

df_modified=df.dropna(subset = ['A', 'B', 'C', 'D', 'E', 'F', 'G']) #filter out rows that have NA in the listed columns
df_modified['A'].value_counts() #count the rows

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM