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   |
|--------------:|---------------:|-----------:|---------------:|---------------:|:-------------|
|       3149506 |             13 |         39 |            262 |             24 | A            |
|      49178715 |           6057 |         23 |           9981 |             25 | I            |
|      23558024 |           6057 |         35 |            157 |             24 | A            |
|      12143552 |             13 |         59 |           8612 |             23 | I            |
|      12824728 |             13 |         49 |           2107 |             24 | A            |
|       1754805 |             13 |         92 |           4000 |             21 | A            |
|      33563649 |             13 |         23 |           1646 |             25 | A            |
|      16530691 |             16 |         56 |           6054 |             24 | A            |
|      10892349 |             13 |         48 |           3031 |             15 | A            |
|      26011974 |           6057 |         39 |           9613 |             24 | I            |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|          COD_IDCONTRA |   COD_PERSONA | FAP_CONTR   |   IMP_CAPDIS |   IMP_CAPINI |   IMP_CAPPEN |
|----------------------:|--------------:|:------------|-------------:|-------------:|-------------:|
|              25336041 |      16772868 | 01MAY1997   |      45977.4 |     45977.4  |       324.32 |
|             287691235 |       7543107 | 29JUN2012   |     115575   |    115575    |     83538.4  |
| 100000000000247300096 |         28522 | 17NOV2014   |      20000   |     20000    |         0    |
|             283248495 |      42709588 | 24SEP2010   |     135000   |    135000    |    114015    |
|             269085475 |       1749947 | 07DEC2015   |       2000   |      2000    |       782.58 |
|             370195336 |      31876190 | 01FEB2017   |          0   |       370.84 |       249.06 |
|              22427895 |      12593539 | 16OCT2009   |     173557   |    173557    |    149180    |
|              25759718 |      12108815 | 06MAR2003   |      51730.7 |     51730.7  |     20453.4  |
|             360337102 |      16793998 | 19SEP2016   |      16536.7 |     16536.7  |     15828.8  |
|             272207668 |      22587973 | 11JAN2016   |          0   |         0    |         0    |


Table #3
Filename: source_2.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 #4
Filename: source_3.csv
Sample Rows in Markdown:
|   COD_PERSONA | XTI_ESTADO   |   QNU_ORDTIT | COD_INTERV   |   COD_IDCONTRA |
|--------------:|:-------------|-------------:|:-------------|---------------:|
|      38511499 | A            |            1 | ASE          |      360148420 |
|      34604927 | A            |            1 | ASE          |      368975004 |
|      44993961 | I            |            1 | PAU          |      373826193 |
|      24234286 | I            |            1 | TIT          |      278583827 |
|      23752360 | A            |            1 | TIT          |      163646343 |
|      31888344 | A            |            1 | TIT          |      356598119 |
|      20384050 | A            |            1 | REP          |        3818531 |
|      45550736 | A            |            1 | TIT          |      284797180 |
|      18474943 | A            |            1 | TIT          |       67013213 |
|      18141809 | C            |            1 | TIT          |      283512505 |


Target Schema:
| FAP_CONTR   | COD_INTERV   |   COD_PERSONA |   COD_AREANEGO |   COD_EDAD |   COD_OFICIPAL |   COD_SEGLOBAL |   estado_cli |   COD_OFICI |   COD_NIVELOFIC |   des_ofici |   cod_cbc |   des_cbc |   cod_zona |   des_zona |   COD_TERRIT |   des_territ |   cod_areanego |   des_areanego |   COD_IDCONTRA |   COD_PERSONA_x |   IMP_CAPDIS |   IMP_CAPINI |   IMP_CAPPEN |   COD_PERSONA_y |   XTI_ESTADO |   QNU_ORDTIT |
|:------------|:-------------|--------------:|---------------:|-----------:|---------------:|---------------:|-------------:|------------:|----------------:|------------:|----------:|----------:|-----------:|-----------:|-------------:|-------------:|---------------:|---------------:|---------------:|----------------:|-------------:|-------------:|-------------:|----------------:|-------------:|-------------:|
| 01APR1984   | TIT          |             1 |              1 |          1 |              1 |              1 |            1 |           1 |               1 |           1 |         1 |         1 |          1 |          1 |            1 |            1 |              1 |              1 |              1 |               1 |            1 |            1 |            1 |               1 |            1 |            1 |
| 01APR1986   | TIT          |             1 |              1 |          1 |              1 |              1 |            1 |           1 |               1 |           1 |         1 |         1 |          1 |          1 |            1 |            1 |              1 |              1 |              1 |               1 |            1 |            1 |            1 |               1 |            1 |            1 |
| 01APR2004   | TIT          |             3 |              3 |          3 |              3 |              3 |            3 |           3 |               3 |           3 |         3 |         3 |          3 |          3 |            3 |            3 |              3 |              3 |              3 |               3 |            3 |            3 |            3 |               3 |            3 |            3 |
| 01APR2005   | TIT          |             2 |              2 |          2 |              2 |              2 |            2 |           2 |               2 |           2 |         2 |         2 |          2 |          2 |            2 |            2 |              2 |              2 |              2 |               2 |            2 |            2 |            2 |               2 |            2 |            2 |
| 01APR2008   | TIT          |             1 |              1 |          1 |              1 |              1 |            1 |           1 |               1 |           1 |         1 |         1 |          1 |          1 |            1 |            1 |              1 |              1 |              1 |               1 |            1 |            1 |            1 |               1 |            1 |            1 |
| 01APR2009   | TIT          |             1 |              1 |          1 |              1 |              1 |            1 |           1 |               1 |           1 |         1 |         1 |          1 |          1 |            1 |            1 |              1 |              1 |              1 |               1 |            1 |            1 |            1 |               1 |            1 |            1 |
| 01APR2010   | TIT          |             1 |              1 |          1 |              1 |              1 |            1 |           1 |               1 |           1 |         1 |         1 |          1 |          1 |            1 |            1 |              1 |              1 |              1 |               1 |            1 |            1 |            1 |               1 |            1 |            1 |
| 01APR2014   | TIT          |             1 |              1 |          1 |              1 |              1 |            1 |           1 |               1 |           1 |         1 |         1 |          1 |          1 |            1 |            1 |              1 |              1 |              1 |               1 |            1 |            1 |            1 |               1 |            1 |            1 |
| 01APR2015   | PAU          |             2 |              2 |          2 |              2 |              2 |            2 |           2 |               2 |           2 |         2 |         2 |          2 |          2 |            2 |            2 |              2 |              2 |              2 |               2 |            2 |            2 |            2 |               2 |            2 |            2 |
| 01APR2015   | REP          |             1 |              1 |          1 |              1 |              1 |            1 |           1 |               1 |           1 |         1 |         1 |          1 |          1 |            1 |            1 |              1 |              1 |              1 |               1 |            1 |            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