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:
|   N.° | Municipio   | Departamento       | Población cabecera   | Población resto   | Población Total   |
|------:|:------------|:-------------------|:---------------------|:------------------|:------------------|
|    72 | Los Patios  | Norte de Santander | 94 847               | 2 373             | 97 220            |
|    73 | Arauca      | Arauca             | 83 256               | 13 558            | 96 814            |
|    74 | Caucasia    | Antioquia          | 84 654               | 10 773            | 95 427            |
|    75 | Tierralta   | Córdoba            | 43 553               | 51 624            | 95 177            |
|    76 | Candelaria  | Valle del Cauca    | 23 940               | 70 271            | 94 211            |
|    77 | Manaure     | La Guajira         | 11 284               | 82 147            | 93 431            |
|    78 | Cajicá      | Cundinamarca       | 64 093               | 28 874            | 92 967            |
|    79 | Acacías     | Meta               | 69 715               | 22 114            | 91 829            |
|    80 | Sabaneta    | Antioquia          | 77 424               | 10 557            | 87 981            |
|    81 | Montelíbano | Córdoba            | 63 689               | 22 196            | 85 885            |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|   N.° | Municipio   | Departamento    | Población cabecera   | Población resto   | Población Total   |
|------:|:------------|:----------------|:---------------------|:------------------|:------------------|
|    33 | Uribia      | La Guajira      | 8 989                | 181 095           | 190 084           |
|    34 | Maicao      | La Guajira      | 118 889              | 66 183            | 185 072           |
|    35 | Piedecuesta | Santander       | 150 483              | 32 476            | 182 959           |
|    36 | Tunja       | Boyacá          | 171 461              | 7 802             | 179 263           |
|    37 | Yopal       | Casanare        | 152 421              | 25 267            | 177 688           |
|    38 | Florencia   | Caquetá         | 152 536              | 20 475            | 173 011           |
|    39 | Girón       | Santander       | 152 582              | 19 322            | 171 904           |
|    40 | Jamundí     | Valle del Cauca | 130 114              | 37 033            | 167 147           |
|    41 | Facatativá  | Cundinamarca    | 145 080              | 10 898            | 155 978           |
|    42 | Fusagasugá  | Cundinamarca    | 132 633              | 21 510            | 154 143           |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
|   N.° | Municipio     | Departamento   | Población cabecera   | Población resto   | Población Total   |
|------:|:--------------|:---------------|:---------------------|:------------------|:------------------|
|   631 | Santacruz     | Nariño         | 1 524                | 9 550             | 11 074            |
|   632 | San Sebastián | Cauca          | 668                  | 10 394            | 11 062            |
|   633 | Bolívar       | Santander      | 1 524                | 9 456             | 10 980            |
|   634 | Buenavista    | Sucre          | 8 653                | 2 311             | 10 964            |
|   635 | Arbeláez      | Cundinamarca   | 4 752                | 6 207             | 10 959            |
|   636 | Yacuanquer    | Nariño         | 3 324                | 7 631             | 10 955            |
|   637 | Medio Atrato  | Chocó          | 980                  | 9 950             | 10 930            |
|   638 | Tesalia       | Huila          | 5 409                | 5 514             | 10 923            |
|   639 | Guateque      | Boyacá         | 7 767                | 3 137             | 10 904            |
|   640 | Soplaviento   | Bolívar        | 10 635               | 204               | 10 839            |


Table #4
Filename: source_3.csv
Sample Rows in Markdown:
|   N.° | Municipio    | Departamento       | Población cabecera   | Población resto   | Población Total   |
|------:|:-------------|:-------------------|:---------------------|:------------------|:------------------|
|     1 | Bogotá       | Cundinamarca       | 7 715 778            | 28 177            | 7 743 955         |
|     2 | Medellín     | Antioquia          | 2 490 164            | 43 260            | 2 533 424         |
|     3 | Cali         | Valle del Cauca    | 2 205 680            | 46 936            | 2 252 616         |
|     4 | Barranquilla | Atlántico          | 1 273 646            | 604               | 1 274 250         |
|     5 | Cartagena    | Bolívar            | 914 552              | 114 184           | 1 028 736         |
|     6 | Cúcuta       | Norte de Santander | 748 948              | 28 158            | 777 106           |
|     7 | Soacha       | Cundinamarca       | 749 034              | 4 514             | 753 548           |
|     8 | Soledad      | Atlántico          | 664 141              | 880               | 665 021           |
|     9 | Bucaramanga  | Santander          | 597 316              | 10 112            | 607 428           |
|    10 | Bello        | Antioquia          | 536 427              | 15 727            | 552 154           |


Target Schema:
| Municipio       |   N.° |   Departamento |   Población cabecera |   Población resto |   Población Total |
|:----------------|------:|---------------:|---------------------:|------------------:|------------------:|
| Abejorral       |     1 |              1 |                    1 |                 1 |                 1 |
| Acacías         |     1 |              1 |                    1 |                 1 |                 1 |
| Acandí          |     1 |              1 |                    1 |                 1 |                 1 |
| Acevedo         |     1 |              1 |                    1 |                 1 |                 1 |
| Achí            |     1 |              1 |                    1 |                 1 |                 1 |
| Agua de Dios    |     1 |              1 |                    1 |                 1 |                 1 |
| Aguachica       |     1 |              1 |                    1 |                 1 |                 1 |
| Aguadas         |     1 |              1 |                    1 |                 1 |                 1 |
| Aguazul         |     1 |              1 |                    1 |                 1 |                 1 |
| Agustín Codazzi |     1 |              1 |                    1 |                 1 |                 1 |

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