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:
|   ComunaID | ComunaNombre      |   ProvinciaID |
|-----------:|:------------------|--------------:|
|        173 | 'Molina'          |            31 |
|        174 | 'Rauco'           |            31 |
|        175 | 'Romeral'         |            31 |
|        176 | 'Sagrada Familia' |            31 |
|        177 | 'Teno'            |            31 |
|        178 | 'Vichuquén'       |            31 |
|        179 | 'Colbún'          |            32 |
|        180 | 'Linares'         |            32 |
|        181 | 'Longaví'         |            32 |
|        182 | 'Parral'          |            32 |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|   ProvinciaID | ProvinciaNombre   |   RegionID |
|--------------:|:------------------|-----------:|
|             1 | 'Arica'           |          1 |
|             2 | 'Parinacota'      |          1 |
|             3 | 'Iquique'         |          2 |
|             4 | 'El Tamarugal'    |          2 |
|             5 | 'Antofagasta'     |          3 |
|             6 | 'El Loa'          |          3 |
|             7 | 'Tocopilla'       |          3 |
|             8 | 'Chañaral'        |          4 |
|             9 | 'Copiapó'         |          4 |
|            10 | 'Huasco'          |          4 |


Target Schema:
|   ProvinciaID | ProvinciaNombre   |   RegionID |   ComunaID | ComunaNombre    |
|--------------:|:------------------|-----------:|-----------:|:----------------|
|             1 | 'Arica'           |          1 |          1 | 'Arica'         |
|             1 | 'Arica'           |          1 |          2 | 'Camarones'     |
|             2 | 'Parinacota'      |          1 |          3 | 'General Lagos' |
|             2 | 'Parinacota'      |          1 |          4 | 'Putre'         |
|             3 | 'Iquique'         |          2 |          5 | 'Alto Hospicio' |
|             3 | 'Iquique'         |          2 |          6 | 'Iquique'       |
|             4 | 'El Tamarugal'    |          2 |          7 | 'Camiña'        |
|             4 | 'El Tamarugal'    |          2 |          8 | 'Colchane'      |
|             4 | 'El Tamarugal'    |          2 |          9 | 'Huara'         |
|             4 | 'El Tamarugal'    |          2 |         10 | 'Pica'          |

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
test: test_0.csv
test_1.csv