简体   繁体   English

当且仅当其他列满足特定条件时,Pandas 数据框会计算特定值在列中出现的次数

[英]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.当且仅当其他列 B、C、D、E、F、G 不为空时,尝试计算特定列 A 下具有“1”值的所有行。 Any ideas?有任何想法吗?

Assuming you have a pandas data frame df with columns ABCDEFG假设您有一个带有 ABCDEFG 列的 Pandas 数据框df

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果某些条件满足熊猫,如何翻转列 - How to flip column if certain condition is meet pandas Python Pandas:计算一个数据框中的值出现在另一个数据框中的次数,在多个条件下进行归档 - Python Pandas: Counting how many times value from one data frame appears in another dataframe, filering on multiple conditions 如何基于熊猫中其他列条件对列的某些值求平均值 - How to average certain values of a column based on other columns condition in pandas 计算列在Pandas中包含特定值的次数 - Count how many times a column contains a certain value in Pandas 计算满足熊猫数据框中某些求和条件的行数 - Counting the number of rows that meet certain sum condition in pandas dataframe 仅针对另一列的某个值对除某些列之外的所有列应用条件 - Apply a condition on all but certain columns only for a certain value of another column 在其他列中的某些条件下替换数据框中的项值 - Replacing item values in a data frame on certain condition in other columns 根据行创建数据框,其中哪些列满足特定条件 - Create data frame based on rows, which columns meet a certain condition PYTHON 在一定条件下填充pandas数据框列 - Filling pandas data frame column under certain condition 创建新列,该列是满足特定条件的其他一些列的聚合 - Create new column which is the aggregation of a few other columns who meet certain condition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM