Premium problem126. Order Counts Including Customers With None

Easy Locked

customers has columns customer_id and name. orders has columns order_id and customer_id.

Return a DataFrame with columns customer_id, name and orders counting each customer's orders. Customers who never ordered must appear with 0, as an integer rather than a float. Sort by customer_id and renumber the index from 0.

Counting the merged frame is the trap: a left merge leaves one all-missing row per orderless customer, which size happily counts as 1.

Input

customers =
   customer_id name
0            1  Ann
1            2   Bo
2            3   Cy
orders =
   order_id  customer_id
0         1            1
1         2            1
2         3            3

Output

   customer_id name  orders
0            1  Ann       2
1            2   Bo       0
2            3   Cy       1

Premium problem

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

Implement solve(...)