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 | XTI_ESTADO   |   QNU_ORDTIT | COD_INTERV   |          COD_IDCONTRA |
|--------------:|:-------------|-------------:|:-------------|----------------------:|
|      23037380 | A            |            1 | TIT          | 100000000001194393600 |
|      35134780 | A            |            1 | TIT          |             149297187 |
|      33876000 | C            |            1 | TIT          |             141437400 |
|      31181800 | A            |            1 | TIT          |              16108163 |
|      40599213 | C            |            1 | TIT          |             340793280 |
|      37814214 | A            |            2 | TIT          |             170089514 |
|      22836075 | C            |            1 | TIT          |             261520398 |
|      45180290 | I            |            3 | TIT          |             340826122 |
|      16222762 | A            |            1 | TIT          |             280060864 |
|      23249112 | A            |            1 | TIT          |             242145568 |


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_PERSONA |   COD_AREANEGO |   COD_EDAD |   COD_OFICIPAL |   COD_SEGLOBAL | estado_cli   |
|--------------:|---------------:|-----------:|---------------:|---------------:|:-------------|
|       4019795 |             13 |         51 |            772 |             24 | A            |
|      26986631 |           6057 |         37 |           9981 |             24 | M            |
|      10365647 |           6057 |         44 |           6093 |             24 | I            |
|      21643377 |             13 |         23 |           6492 |             25 | A            |
|      37819780 |             13 |         39 |           8760 |             24 | M            |
|       2694487 |             13 |         45 |           1468 |             24 | A            |
|      12670601 |           6057 |         41 |           9613 |             85 | I            |
|      31233255 |             13 |         60 |           2638 |             23 | A            |
|       3338261 |           4747 |         54 |           4041 |             21 | A            |
|      18085723 |             13 |         60 |           6419 |             23 | M            |


Table #4
Filename: source_3.csv
Sample Rows in Markdown:
|          COD_IDCONTRA |   COD_PERSONA | FAP_CONTR   |   IMP_CAPDIS |   IMP_CAPINI |   IMP_CAPPEN |
|----------------------:|--------------:|:------------|-------------:|-------------:|-------------:|
|             170508993 |      37131530 | 03AUG2009   |      9000    |      9000    |         0    |
|              18050987 |      11968740 | 05JAN2006   |    130000    |    130000    |     72983.3  |
| 100000000000348422144 |       2684514 | 01APR1984   |     13023.9  |     13023.9  |         0    |
|             199263304 |      34315224 | 13JAN2014   |     46000    |     46000    |     38871.6  |
|             358884867 |      12211549 | 22AUG2016   |      6857.73 |      6857.73 |      5373.94 |
|             283689624 |      45165532 | 25JUL2003   |     82459    |     82459    |     31595.8  |
|             366337923 |      18096910 | 02DEC2016   |         0    |       208.11 |       140.79 |
|             275430576 |      33735528 | 03MAR2016   |      6080    |      6080    |      5210.16 |
|             172901691 |        867488 | 29NOV2007   |    100000    |    100000    |     79749.9  |
|             360923616 |       7229169 | 27SEP2016   |         0    |         0    |         0    |


Target Schema:
| des_zona           |   COD_PERSONA_x |   COD_AREANEGO |
|:-------------------|----------------:|---------------:|
| Z. ARABA - BIZKAIA |             231 |            231 |
| Z. ASTURIAS        |             357 |            357 |
| Z. BALEARES        |             355 |            355 |
| Z. BARCELONA EST   |             111 |            111 |
| Z. BARCELONA NORD  |             127 |            127 |
| Z. BARCELONA SUD   |             325 |            325 |
| Z. BESÒS-MARESME   |             196 |            196 |
| Z. GALICIA CENTRO  |             281 |            281 |
| Z. GALICIA NORTE   |             287 |            287 |
| Z. GALICIA SUR     |             391 |            391 |

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