[英]How to count occurrences in a dataframe columns?
This is a sample of my df: 这是我的df的样本:
Paid Scheduled tfl modeName
True True True bus
True True True cable-car
True True False coach
False False False cycle
True False True cycle-hire
True True True dlr
I need to have in another dataframe only the modeName which are true in Paid and Scheduled: 我需要在另一个数据框中仅包含在“付费”和“预定时间”中为true的modeName:
modeName
bus
cable car
coach
dlr
And count how many are paid AND scheduled. 并计算有多少已付款并已安排。 I got this with this code:
我用以下代码得到了这个:
df1_transporte = df1.isFarePaying.values.sum() & df1.isScheduledService.values.sum()
df1_transporte
But how to get the modeNames that have both conditions? 但是,如何获得同时具有这两个条件的modeNames?
Using pandas, 使用大熊猫
you can use df[(df['Paid']==True) & (df['Scheduled']==True)]
to generate a dataframe with only the rows where 'Paid' and 'Scheduled' are True. 您可以使用
df[(df['Paid']==True) & (df['Scheduled']==True)]
生成仅包含“ Paid”和“ Scheduled”为True的行的数据框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.