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:
|   COD_PERSONA |   COD_AREANEGO |   COD_EDAD |   COD_OFICIPAL |   COD_SEGLOBAL | estado_cli   |
|--------------:|---------------:|-----------:|---------------:|---------------:|:-------------|
|       6150963 |             13 |         38 |           7611 |             24 | A            |
|      34114603 |           6057 |         53 |           9981 |             24 | I            |
|      26632270 |             13 |         31 |           2446 |             24 | A            |
|      45652524 |             13 |         59 |           5606 |             81 | M            |
|      29211754 |             13 |         18 |           1817 |             25 | A            |
|      13523953 |             13 |         40 |           2786 |             24 | A            |
|      16251467 |             13 |         50 |            292 |             24 | A            |
|      12008291 |           6057 |         37 |           8248 |             24 | I            |
|       5555293 |           6057 |         64 |           8248 |             23 | I            |
|      45599117 |             13 |         36 |           8747 |             24 | A            |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|   COD_OFICI |   COD_NIVELOFIC | des_ofici                         | cod_cbc   | des_cbc   | cod_zona   | des_zona   |   COD_TERRIT | des_territ   | cod_areanego   | des_areanego   |
|------------:|----------------:|:----------------------------------|:----------|:----------|:-----------|:-----------|-------------:|:-------------|:---------------|:---------------|
|           1 |              70 | BANCO BILBAO VIZCAYA ARGENTARIA   |           |           |            |            |            0 |              |                |                |
|        2004 |              40 | AGREGADO FICT. CARTERA DE TITULOS |           |           |            |            |            0 |              |                |                |
|        2221 |              40 | FRANCIA (R)                       |           |           |            |            |            0 |              |                |                |
|        2222 |              40 | ITALIA (R)                        |           |           |            |            |            0 |              |                |                |
|        2223 |              40 | INGLATERRA (R)                    |           |           |            |            |            0 |              |                |                |
|        2224 |              40 | NUEVA YORK (R)                    |           |           |            |            |            0 |              |                |                |
|        2226 |              40 | JAPON (R)                         |           |           |            |            |            0 |              |                |                |
|        2227 |              40 | BELGICA (R)                       |           |           |            |            |            0 |              |                |                |
|        2246 |              40 | CHINA (R)                         |           |           |            |            |            0 |              |                |                |
|        2385 |              40 | AUSTRALIA                         |           |           |            |            |            0 |              |                |                |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
|   COD_IDCONTRA |   COD_PERSONA | FAP_CONTR   |   IMP_CAPDIS |   IMP_CAPINI |   IMP_CAPPEN |
|---------------:|--------------:|:------------|-------------:|-------------:|-------------:|
|      283381076 |      44168073 | 30NOV2015   |       9000   |       9000   |       7053.6 |
|      356901013 |      18401479 | 15JUL2016   |          0   |          0   |          0   |
|      358923338 |      23968732 | 23AUG2016   |      12326   |      12326   |      11668.9 |
|       21368364 |      30418119 | 22JUN2009   |     150000   |     143500   |      81538.1 |
|      277310652 |       9952674 | 04APR2016   |          0   |          0   |          0   |
|      275451849 |       9208026 | 02MAR2016   |          0   |          0   |          0   |
|       17857260 |      18138091 | 28SEP2006   |      17472.7 |      17472.7 |          0   |
|      137615859 |       8368899 | 18JUL2011   |     124000   |     124000   |      85146.8 |
|      361265893 |      12788753 | 03OCT2016   |          0   |          0   |          0   |
|       20958982 |       7088819 | 29APR2005   |     110000   |     110000   |      29700.2 |


Table #4
Filename: source_3.csv
Sample Rows in Markdown:
|   COD_PERSONA | XTI_ESTADO   |   QNU_ORDTIT | COD_INTERV   |          COD_IDCONTRA |
|--------------:|:-------------|-------------:|:-------------|----------------------:|
|      33776460 | A            |            1 | TIT          |             287649571 |
|      26751538 | I            |            1 | TIT          |             369149518 |
|      44472159 | A            |            1 | TIT          |             284882494 |
|      30972573 | C            |            1 | TIT          |             195648944 |
|      29427411 | C            |            1 | TIT          |             251699474 |
|      19312456 | C            |            1 | TIT          | 100000000000514768896 |
|      37819650 | A            |            1 | TIT          |             271225569 |
|      24909518 | C            |            1 | TIT          |             175789147 |
|      24466968 | C            |            1 | TIT          |             329955400 |
|      37337135 | A            |            1 | TIT          | 100000000001308737536 |


Target Schema:
| des_zona           |   COD_PERSONA_x |   COD_AREANEGO |
|:-------------------|----------------:|---------------:|
| Z. ARABA - BIZKAIA |        15614314 |             13 |
| Z. ASTURIAS        |        15555022 |             13 |
| Z. BALEARES        |        15510840 |             13 |
| Z. BARCELONA EST   |        15466517 |             13 |
| Z. BARCELONA NORD  |        15463465 |             13 |
| Z. BARCELONA SUD   |        15360476 |             13 |
| Z. BESÒS-MARESME   |        15594369 |             13 |
| Z. GALICIA CENTRO  |        15603266 |             13 |
| Z. GALICIA NORTE   |        15602474 |             13 |
| Z. GALICIA SUR     |        15607246 |             13 |

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