Premium problem99. Distinct Streets per Postal Code

Medium Locked

addresses has columns postal_code and street_name.

Treat the first word of street_name as the street, so "Market St" and "Market Avenue" are the same street. Return a DataFrame with columns postal_code and streets giving the number of distinct streets in each postal code, sorted by postal_code, with the index renumbered from 0.

Input

  postal_code    street_name
0       94107      Market St
1       94107  Market Avenue
2       94107      Bryant St
3       94110    Valencia St

Output

  postal_code  streets
0       94107        2
1       94110        1

Premium problem

This one's part of Premium. Unlock the full Pandas track plus every other premium problem on the site.

Implement solve(...)