简体   繁体   English

Python - Pandas - Dataframe 如何在使用.count时将notnull添加到列

[英]Python - Pandas - Dataframe How to add notnull to a column when using .count

I am creating a new column that will count all ids but exclude a few rows of customers where the customer's ID has a certain prefix and has no repeat orders我正在创建一个新列,该列将计算所有 ID,但排除几行客户 ID 具有特定前缀且没有重复订单的客户

df['newcolumn'] = df[(df.notnull['Date']) & (df['ID'].str.contains('prefix')) & (df['Repeat order'] == 'No')].groupby(['ID'], as_index=False).count()

I am getting below error我得到以下错误

TypeError: 'method' object is not subscriptable

Still no difference when I replaced [] with () to resolve above error当我用 () 替换 [] 来解决上述错误时仍然没有区别

change改变

df.notnull['Date']

to

df['Date'].notnull()

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

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