Skip to content
Advertisement

Count Number of Rows within Time Interval in Pandas Dataframe

Say we have this data:

JavaScript

I want to count, for each year, how many rows (“index”) fall within each year, but excluding the Y0.

So say we start at the first available year, 1990:

How many rows do we count? 0.

1991:

  • Three (row 1, 2, 3)

1992:

  • Four (row 1, 2, 3, 4)

2009:

  • Four (row 1, 2, 3, 4)

So I want to end up with a dataframe that says:

JavaScript

My attempt:

JavaScript

But the result doesn’t look right.

Appreciate any help.

Advertisement

Answer

you could do:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement