Jan-05-2024, 06:43 AM
(This post was last modified: Jan-05-2024, 06:43 AM by deanhystad.)
You can do something like this:
import pandas as pd df = pd.read_csv("parties.csv") df = df.groupby(['COUNTRY', 'PTYNAME'])['YEAR'].count() print(df)And get something like this:
Output:COUNTRY PTYNAME
Finland Finns Party 1
National Coalition Party 1
Social Democratic Party of Finland 1
Norway Centre Party 1
Green League 1
But this is no longer a dataframe, it is a multiindexed series.