Distinct Languages Spoken by Each Guide
Problem
You are given a DataFrame `guide_languages` with columns `guide_id`, `language_id`, and `region_id`. The same guide can be recorded speaking the same language in several regions. Return a DataFrame with columns `guide_id` and `language_count`, where `language_count` is the number of distinct languages each guide speaks. Row order does not matter.
Input data
Example rows — the live problem includes the full dataset.
guide_languages
| guide_id | language_id | region_id |
|---|---|---|
| 1 | 2 | 3 |
| 1 | 2 | 4 |
| 1 | 3 | 3 |
| 2 | 1 | 1 |
| 2 | 2 | 1 |
Expected output
Your answer should return 2 rows with the columns guide_id, language_count.
Starter code (Pandas (Python))
import pandas as pd
def distinct_languages(guide_languages) -> pd.DataFrame:
# Your code here
return guide_languagesSolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock