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:
| 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 #2
Filename: source_1.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 |


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   |


Target Schema:
| Ord_id   | Prod_id   | Ship_id   | Cust_id   |    Sales |   Discount |   Order_Quantity |   Profit |   Shipping_Cost |   Product_Base_Margin | Product_Category   | Product_Sub_Category          | Customer_Name   | Province   | Region   | Customer_Segment   |
|:---------|:----------|:----------|:----------|---------:|-----------:|-----------------:|---------:|----------------:|----------------------:|:-------------------|:------------------------------|:----------------|:-----------|:---------|:-------------------|
| Ord_5446 | Prod_16   | SHP_7609  | Cust_1818 |  136.81  |       0.01 |               23 |   -30.51 |            3.6  |                  0.56 | OFFICE SUPPLIES    | SCISSORS, RULERS AND TRIMMERS | AARON BERGMAN   | ALBERTA    | WEST     | CORPORATE          |
| Ord_5406 | Prod_13   | SHP_7549  | Cust_1818 |   42.27  |       0.01 |               13 |     4.56 |            0.93 |                  0.54 | OFFICE SUPPLIES    | PENS & ART SUPPLIES           | AARON BERGMAN   | ALBERTA    | WEST     | CORPORATE          |
| Ord_5446 | Prod_4    | SHP_7610  | Cust_1818 | 4701.69  |       0    |               26 |  1148.9  |            2.5  |                  0.59 | TECHNOLOGY         | TELEPHONES AND COMMUNICATION  | AARON BERGMAN   | ALBERTA    | WEST     | CORPORATE          |
| Ord_5456 | Prod_6    | SHP_7625  | Cust_1818 | 2337.89  |       0.09 |               43 |   729.34 |           14.3  |                  0.37 | OFFICE SUPPLIES    | PAPER                         | AARON BERGMAN   | ALBERTA    | WEST     | CORPORATE          |
| Ord_5446 | Prod_6    | SHP_7608  | Cust_1818 |  164.02  |       0.03 |               23 |   -47.64 |            6.15 |                  0.37 | OFFICE SUPPLIES    | PAPER                         | AARON BERGMAN   | ALBERTA    | WEST     | CORPORATE          |
| Ord_5485 | Prod_17   | SHP_7664  | Cust_1818 | 4233.15  |       0.08 |               35 |  1219.87 |           26.3  |                  0.38 | TECHNOLOGY         | OFFICE MACHINES               | AARON BERGMAN   | ALBERTA    | WEST     | CORPORATE          |
| Ord_2978 | Prod_16   | SHP_4112  | Cust_1088 |  305.05  |       0.04 |               27 |    23.12 |            3.37 |                  0.57 | OFFICE SUPPLIES    | SCISSORS, RULERS AND TRIMMERS | AARON HAWKINS   | ONTARIO    | ONTARIO  | HOME OFFICE        |
| Ord_5484 | Prod_16   | SHP_7663  | Cust_1820 |  322.82  |       0.05 |               35 |   -17.58 |            3.98 |                  0.56 | OFFICE SUPPLIES    | SCISSORS, RULERS AND TRIMMERS | ADRIAN SHAMI    | ALBERTA    | WEST     | CONSUMER           |
| Ord_5430 | Prod_4    | SHP_7588  | Cust_1820 |  337.204 |       0.09 |                9 |  -120.93 |            4.99 |                  0.56 | TECHNOLOGY         | TELEPHONES AND COMMUNICATION  | ADRIAN SHAMI    | ALBERTA    | WEST     | CONSUMER           |
| Ord_5462 | Prod_4    | SHP_7632  | Cust_1820 |  175.857 |       0.03 |               10 |   -93.26 |            1.25 |                  0.83 | TECHNOLOGY         | TELEPHONES AND COMMUNICATION  | ADRIAN SHAMI    | ALBERTA    | WEST     | CONSUMER           |

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