Skip to content

Commit

Permalink
patch value counts issue in merge lecture
Browse files Browse the repository at this point in the history
  • Loading branch information
doctor-phil committed Oct 25, 2024
1 parent 5ef2c15 commit c3bb327
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lectures/pandas/merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,13 @@ a future lecture.
```{code-cell} python
users_by_n = (
ratings["user_id"]
.value_counts() # Series. Index: user_id, value: n ratings by user
.value_counts() # Series. Index: n_ratings by user, value: N_users with this many ratings
.value_counts() # Series called "count". Index: user_id, value: n ratings by user
.rename("N_ratings") # Rename the Series to "N_ratings"
.value_counts() # Series called "count". Index: n_ratings by user, value: N_users with this many ratings
.sort_index() # Sort our Series by the index (number of ratings)
.reset_index() # Dataframe with columns `index` (from above) and `user_id`
.rename(columns={"index": "N_ratings", "user_id": "N_users"})
.rename(columns={"count": "N_users"})
.set_index("N_ratings")
)
users_by_n.head(10)
```
Expand Down

0 comments on commit c3bb327

Please sign in to comment.