I would like to count the number of record in dataframe2 and add the count to the corresponding rows in dataframe1.
The first one (df1)
| Road | RoadNo | Count |
|---|---|---|
| A | 1 | 0 |
| A | 2 | 0 |
| B | 1 | 0 |
| B | 2 | 0 |
The second one (df2)
| Road | RoadNo |
|---|---|
| A | 1 |
| A | 1 |
| A | 1 |
| A | 2 |
| A | 2 |
| B | 1 |
The expected output is to count the number of records in dataframe2 and add that number to the corresponding Road and RoadNo rows in dataframe1.
Expected Output:
| Road | RoadNo | Count |
|---|---|---|
| A | 1 | 3 |
| A | 2 | 2 |
| B | 1 | 1 |
| B | 2 | 0 |
Is there a function in Pandas or Python that can help me with this operation? Do I need to create two tables in the database and execute the SQL query to perform this operation? Many Thanks!