I am working with two columns in a table.
+-------------+--------------------------------------------------------------+
| Area Name | Code Description |
+-------------+--------------------------------------------------------------+
| N Hollywood | VIOLATION OF RESTRAINING ORDER |
| N Hollywood | CRIMINAL THREATS - NO WEAPON DISPLAYED |
| N Hollywood | CRIMINAL THREATS - NO WEAPON DISPLAYED |
| N Hollywood | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT |
| Southeast | ASSAULT WITH DEADLY WEAPON, AGGRAVATED ASSAULT |
| West Valley | CRIMINAL THREATS - NO WEAPON DISPLAYED |
| West Valley | CRIMINAL THREATS - NO WEAPON DISPLAYED |
| 77th Street | RAPE, FORCIBLE |
| Foothill | CRM AGNST CHLD (13 OR UNDER) (14-15 & SUSP 10 YRS OLDER)0060 |
| N Hollywood | VANDALISM - FELONY ($400 & OVER, ALL CHURCH VANDALISMS) 0114 |
+-------------+--------------------------------------------------------------+
I'm using the Groupby and value_counts to find Code Descriptions by Area Name.
df.groupby(['Area Name'])['Code Description'].value_counts()
Is there a way to view only the top 'n' values per Area Name? If I append .nlargest(3)
to the code above it only returns result for one Area Name.
+---------------------------------------------------------------------------------+
| Wilshire SHOPLIFTING-GRAND THEFT ($950.01 & OVER) 7 |
+---------------------------------------------------------------------------------+