Skip to content
Advertisement

How do I count the amount of times a unique value in a dataframe meets a requirement?

I have a total of about 9000 rows and 26 different units in the df. An example of the df is below:

Unit Total_time
E271 0 days 00:05:32

I want to create a column with the amount of times each unit appears in the df and a separate one that counts the amount of times each unit’s time is under 6 min. The new df should look like this:

Unit Total_dispatches Amount_time_under Perc_success_rate
E271 1154 883 76.5%

Any help would be appreciated!

Advertisement

Answer

You can do it something like this:

JavaScript
Advertisement