Task: Transform-by-output-target-schema (source dataset: commercial-pipelines)

Your task is to create a data transformation pipeline in Python using pandas libraries.

Given Source Tables below, and a Target Schema provided by users that demonstrates how the desired output table should look like schematically, please write Python pandas code that can transform the Source Tables into an output table, that matches the schema/structure given by the Target Schema.  Please note that the data values in the Target Schema are intended to represent the format and layout of the output table, but may not exactly match the actual data generated from the Source Tables when the python code is run on the Source Tables.

Use operations such as merge, groupby, pivot, apply, or any appropriate python or pandas steps. Your code should save the resulting DataFrame to a CSV file named 'output.csv'. Ensure that the code is executable and can be run directly as is, in a Python environment with pandas installed.

Source Tables:


Table #1
Filename: source_0.csv
Sample Rows in Markdown:
|   OrderID | CustomerID   |   EmployeeID | OrderDate      | RequiredDate   | ShippedDate    |   ShipVia |   Freight | ShipName                  | ShipAddress                                | ShipCity       | ShipRegion   | ShipPostalCode   | ShipCountry   |
|----------:|:-------------|-------------:|:---------------|:---------------|:---------------|----------:|----------:|:--------------------------|:-------------------------------------------|:---------------|:-------------|:-----------------|:--------------|
|     10248 | VINET        |            5 | 7/4/1996 0:00  | 8/1/1996 0:00  | 7/16/1996 0:00 |         3 |     32.38 | Vins et alcools Chevalier | 59 rue de l'Abbaye                         | Reims          |              | 51100            | France        |
|     10249 | TOMSP        |            6 | 7/5/1996 0:00  | 8/16/1996 0:00 | 7/10/1996 0:00 |         1 |     11.61 | Toms Spezialitäten        | Luisenstr. 48                              | Münster        |              | 44087            | Germany       |
|     10250 | HANAR        |            4 | 7/8/1996 0:00  | 8/5/1996 0:00  | 7/12/1996 0:00 |         2 |     65.83 | Hanari Carnes             | Rua do Paço, 67                            | Rio de Janeiro | RJ           | 05454-876        | Brazil        |
|     10251 | VICTE        |            3 | 7/8/1996 0:00  | 8/5/1996 0:00  | 7/15/1996 0:00 |         1 |     41.34 | Victuailles en stock      | 2, rue du Commerce                         | Lyon           |              | 69004            | France        |
|     10252 | SUPRD        |            4 | 7/9/1996 0:00  | 8/6/1996 0:00  | 7/11/1996 0:00 |         2 |     51.3  | Suprêmes délices          | Boulevard Tirou, 255                       | Charleroi      |              | B-6000           | Belgium       |
|     10253 | HANAR        |            3 | 7/10/1996 0:00 | 7/24/1996 0:00 | 7/16/1996 0:00 |         2 |     58.17 | Hanari Carnes             | Rua do Paço, 67                            | Rio de Janeiro | RJ           | 05454-876        | Brazil        |
|     10254 | CHOPS        |            5 | 7/11/1996 0:00 | 8/8/1996 0:00  | 7/23/1996 0:00 |         2 |     22.98 | Chop-suey Chinese         | Hauptstr. 31                               | Bern           |              | 3012             | Switzerland   |
|     10255 | RICSU        |            9 | 7/12/1996 0:00 | 8/9/1996 0:00  | 7/15/1996 0:00 |         3 |    148.33 | Richter Supermarkt        | Starenweg 5                                | Genève         |              | 1204             | Switzerland   |
|     10256 | WELLI        |            3 | 7/15/1996 0:00 | 8/12/1996 0:00 | 7/17/1996 0:00 |         2 |     13.97 | Wellington Importadora    | Rua do Mercado, 12                         | Resende        | SP           | 08737-363        | Brazil        |
|     10257 | HILAA        |            4 | 7/16/1996 0:00 | 8/13/1996 0:00 | 7/22/1996 0:00 |         3 |     81.91 | HILARION-Abastos          | Carrera 22 con Ave. Carlos Soublette #8-35 | San Cristóbal  | Táchira      | 5022             | Venezuela     |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|   OrderID |   ProductID |   UnitPrice |   Quantity |   Discount |
|----------:|------------:|------------:|-----------:|-----------:|
|     10673 |          16 |       17.45 |          3 |       0    |
|     10750 |          14 |       23.25 |          5 |       0.15 |
|     10453 |          70 |       12    |         25 |       0.1  |
|     10948 |          55 |       24    |          4 |       0    |
|     11030 |          59 |       55    |        100 |       0.25 |
|     10357 |          26 |       24.9  |         16 |       0    |
|     10989 |           6 |       25    |         40 |       0    |
|     10512 |          60 |       34    |         12 |       0.15 |
|     10507 |          48 |       12.75 |         15 |       0.15 |
|     10314 |          58 |       10.6  |         30 |       0.1  |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
|   ProductID | ProductName                     |   SupplierID |   CategoryID | QuantityPerUnit     |   UnitPrice |   UnitsInStock |   UnitsOnOrder |   ReorderLevel | Discontinued   |
|------------:|:--------------------------------|-------------:|-------------:|:--------------------|------------:|---------------:|---------------:|---------------:|:---------------|
|           1 | Chai                            |            1 |            1 | 10 boxes x 20 bags  |       18    |             39 |              0 |             10 | False          |
|           2 | Chang                           |            1 |            1 | 24 - 12 oz bottles  |       19    |             17 |             40 |             25 | False          |
|           3 | Aniseed Syrup                   |            1 |            2 | 12 - 550 ml bottles |       10    |             13 |             70 |             25 | False          |
|           4 | Chef Anton's Cajun Seasoning    |            2 |            2 | 48 - 6 oz jars      |       22    |             53 |              0 |              0 | False          |
|           5 | Chef Anton's Gumbo Mix          |            2 |            2 | 36 boxes            |       21.35 |              0 |              0 |              0 | True           |
|           6 | Grandma's Boysenberry Spread    |            3 |            2 | 12 - 8 oz jars      |       25    |            120 |              0 |             25 | False          |
|           7 | Uncle Bob's Organic Dried Pears |            3 |            7 | 12 - 1 lb pkgs.     |       30    |             15 |              0 |             10 | False          |
|           8 | Northwoods Cranberry Sauce      |            3 |            2 | 12 - 12 oz jars     |       40    |              6 |              0 |              0 | False          |
|           9 | Mishi Kobe Niku                 |            4 |            6 | 18 - 500 g pkgs.    |       97    |             29 |              0 |              0 | True           |
|          10 | Ikura                           |            4 |            8 | 12 - 200 ml jars    |       31    |             31 |              0 |              0 | False          |


Target Schema:
|   ProductID |   year |   ('OrderID', 'count') |
|------------:|-------:|-----------------------:|
|           1 |   1997 |                      9 |
|           1 |   1998 |                     11 |
|           2 |   1996 |                      4 |
|           2 |   1997 |                     10 |
|           2 |   1998 |                     10 |
|           3 |   1997 |                      4 |
|           3 |   1998 |                      3 |
|           4 |   1996 |                      3 |
|           4 |   1997 |                      5 |
|           4 |   1998 |                      2 |

Return only the final code in markdown codeblock format, without any additional text or explanation. 



target: target.csv
train: source_0.csv
source_1.csv
source_2.csv
test: test_0.csv
test_1.csv
test_2.csv