Task: Transform-by-output-target-schema (source dataset: github-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:
| Order_Date   | Order_Priority   | Ord_id   |
|:-------------|:-----------------|:---------|
| 13-10-2010   | LOW              | Ord_1    |
| 01-10-2012   | HIGH             | Ord_2    |
| 10-07-2011   | HIGH             | Ord_3    |
| 28-08-2010   | NOT SPECIFIED    | Ord_4    |
| 17-06-2011   | HIGH             | Ord_5    |
| 24-03-2011   | HIGH             | Ord_6    |
| 26-02-2010   | LOW              | Ord_7    |
| 23-11-2010   | MEDIUM           | Ord_8    |
| 08-06-2012   | NOT SPECIFIED    | Ord_9    |
| 04-08-2012   | NOT SPECIFIED    | Ord_10   |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
| Customer_Name      | Province   | Region   | Customer_Segment   | Cust_id   |
|:-------------------|:-----------|:---------|:-------------------|:----------|
| MUHAMMED MACINTYRE | NUNAVUT    | NUNAVUT  | SMALL BUSINESS     | Cust_1    |
| BARRY FRENCH       | NUNAVUT    | NUNAVUT  | CONSUMER           | Cust_2    |
| CLAY ROZENDAL      | NUNAVUT    | NUNAVUT  | CORPORATE          | Cust_3    |
| CARLOS SOLTERO     | NUNAVUT    | NUNAVUT  | CONSUMER           | Cust_4    |
| CARL JACKSON       | NUNAVUT    | NUNAVUT  | CORPORATE          | Cust_5    |
| MONICA FEDERLE     | NUNAVUT    | NUNAVUT  | CORPORATE          | Cust_6    |
| DOROTHY BADDERS    | NUNAVUT    | NUNAVUT  | HOME OFFICE        | Cust_7    |
| NEOLA SCHNEIDER    | NUNAVUT    | NUNAVUT  | HOME OFFICE        | Cust_8    |
| CARLOS DALY        | NUNAVUT    | NUNAVUT  | HOME OFFICE        | Cust_9    |
| CLAUDIA MINER      | NUNAVUT    | NUNAVUT  | SMALL BUSINESS     | Cust_10   |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
| Product_Category   | Product_Sub_Category           | Prod_id   |
|:-------------------|:-------------------------------|:----------|
| OFFICE SUPPLIES    | STORAGE & ORGANIZATION         | Prod_1    |
| OFFICE SUPPLIES    | APPLIANCES                     | Prod_2    |
| OFFICE SUPPLIES    | BINDERS AND BINDER ACCESSORIES | Prod_3    |
| TECHNOLOGY         | TELEPHONES AND COMMUNICATION   | Prod_4    |
| FURNITURE          | OFFICE FURNISHINGS             | Prod_5    |
| OFFICE SUPPLIES    | PAPER                          | Prod_6    |
| OFFICE SUPPLIES    | RUBBER BANDS                   | Prod_7    |
| TECHNOLOGY         | COMPUTER PERIPHERALS           | Prod_8    |
| OFFICE SUPPLIES    | ENVELOPES                      | Prod_9    |
| FURNITURE          | BOOKCASES                      | Prod_10   |


Table #4
Filename: source_3.csv
Sample Rows in Markdown:
| Ship_Mode      | Ship_Date   | Ship_id   |
|:---------------|:------------|:----------|
| REGULAR AIR    | 20-10-2010  | SHP_1     |
| DELIVERY TRUCK | 02-10-2012  | SHP_2     |
| REGULAR AIR    | 03-10-2012  | SHP_3     |
| REGULAR AIR    | 12-07-2011  | SHP_4     |
| REGULAR AIR    | 30-08-2010  | SHP_5     |
| REGULAR AIR    | 17-06-2011  | SHP_6     |
| REGULAR AIR    | 18-06-2011  | SHP_7     |
| EXPRESS AIR    | 25-03-2011  | SHP_8     |
| REGULAR AIR    | 26-02-2010  | SHP_9     |
| REGULAR AIR    | 24-11-2010  | SHP_10    |


Table #5
Filename: source_4.csv
Sample Rows in Markdown:
| Ord_id   | Prod_id   | Ship_id   | Cust_id   |    Sales |   Discount |   Order_Quantity |   Profit |   Shipping_Cost |   Product_Base_Margin |
|:---------|:----------|:----------|:----------|---------:|-----------:|-----------------:|---------:|----------------:|----------------------:|
| Ord_1082 | Prod_8    | SHP_1495  | Cust_417  |   240.63 |       0.02 |               31 |  -117.92 |            5.53 |                  0.69 |
| Ord_1080 | Prod_2    | SHP_1493  | Cust_415  |  7512.03 |       0.09 |               21 |  2017.64 |           19.99 |                  0.57 |
| Ord_3538 | Prod_3    | SHP_4899  | Cust_1269 |   320.26 |       0.01 |               43 |   -84.13 |            6.05 |                  0.39 |
| Ord_3555 | Prod_8    | SHP_4923  | Cust_1269 |  1841.6  |       0.01 |               36 |    12.95 |            6.5  |                  0.73 |
| Ord_3560 | Prod_15   | SHP_4930  | Cust_1269 |  7264.64 |       0.06 |               35 |  1845.68 |           18.06 |                  0.57 |
| Ord_292  | Prod_16   | SHP_394   | Cust_44   |   600.22 |       0.08 |               50 |    27.86 |            3.14 |                  0.6  |
| Ord_140  | Prod_9    | SHP_187   | Cust_44   |   317.85 |       0.06 |               28 |   -13.95 |            6.97 |                  0.35 |
| Ord_140  | Prod_12   | SHP_188   | Cust_44   |   163.08 |       0.09 |               42 |    66.17 |            0.5  |                  0.39 |
| Ord_59   | Prod_6    | SHP_79    | Cust_44   |   101.21 |       0.1  |                5 |     2.13 |            5.21 |                  0.37 |
| Ord_59   | Prod_15   | SHP_78    | Cust_44   | 12175.8  |       0.02 |               36 |  2825.15 |           58.95 |                  0.57 |


Target Schema:
| Customer_Segment   |   Ord_id |   Prod_id |   Ship_id |   Cust_id |
|:-------------------|---------:|----------:|----------:|----------:|
| CONSUMER           |      780 |       780 |       780 |       780 |
| CORPORATE          |     1501 |      1501 |      1501 |      1501 |
| HOME OFFICE        |      930 |       930 |       930 |       930 |
| SMALL BUSINESS     |      988 |       988 |       988 |       988 |

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
source_3.csv
source_4.csv
test: test_0.csv
test_1.csv
test_2.csv
test_3.csv
test_4.csv