I am trying to group this data frame from CSV file. It is a long data frame with multiple countries under the column COUNTRY and corresponding different party names under the column PTYNAME.
but as a result, all party names get packed against each other in a single row.
Was wondering if anyone has any idea. let me know if I need to clarify anything.
Output:COUNTRY CTRYID YEAR PTYNAME
Finland 7.0 2017 Centre Party
Finland 7.0 2017 Finns Party
Finland 7.0 2017 National Coalition Party
Finland 7.0 2017 Social Democratic Party of Finland
Finland 7.0 2017 Green League
What I'd like to do is create a multi-index data frame where I have shown different party names under one country name. something like this below:Output:COUNTRY PTYNAME
Centre Party
Finns Party
Finland National Coalition Party
Social Democratic Party of Finland
Green League
I used the method below:df1 = df.groupby(['COUNTRY'])['PTYNAME'].sum()
but as a result, all party names get packed against each other in a single row.
Was wondering if anyone has any idea. let me know if I need to clarify anything.