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   |
|--------------:|---------------:|-----------:|---------------:|---------------:|:-------------|
|       1153473 |             13 |         85 |            507 |             23 | A            |
|      27824647 |             13 |         43 |           7747 |             14 | A            |
|      14298911 |             13 |         22 |            628 |             86 | A            |
|      12752255 |           6057 |         68 |           9534 |             23 | I            |
|      44290669 |             13 |         58 |           4611 |             14 | A            |
|      35362970 |           6057 |         49 |           9613 |             81 | I            |
|       9555517 |             13 |         60 |           1630 |             15 | A            |
|      44146343 |             13 |         20 |           3385 |             25 | A            |
|       4930301 |             13 |         39 |           6884 |             24 | A            |
|      19724082 |             13 |         83 |           3230 |             22 | 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 |
|---------------:|--------------:|:------------|-------------:|-------------:|-------------:|
|      366440394 |      37907066 | 05DEC2016   |          0   |       360    |       121.78 |
|      178443530 |      31058151 | 01SEP1998   |      63106.3 |     63106.3  |         0    |
|       19597723 |       5976470 | 23OCT2003   |     132222   |    132222    |     26915.6  |
|      267290189 |      30771268 | 05NOV2015   |          0   |         0    |         0    |
|      366871278 |      12512724 | 13DEC2016   |       3760   |      3760    |         0    |
|       78259130 |      19326533 | 08FEB2010   |      31014.9 |     31014.9  |      5001.26 |
|      370499896 |       9645464 | 06FEB2017   |          0   |       125.75 |       125.75 |
|      360785975 |      19166041 | 26SEP2016   |          0   |         0    |         0    |
|      370106350 |      31862408 | 31JAN2017   |          0   |       370.41 |       248.77 |
|       97402979 |      24300981 | 14SEP2010   |     114500   |    114500    |     85911.8  |


Table #4
Filename: source_3.csv
Sample Rows in Markdown:
|   COD_PERSONA | XTI_ESTADO   |   QNU_ORDTIT | COD_INTERV   |          COD_IDCONTRA |
|--------------:|:-------------|-------------:|:-------------|----------------------:|
|      26784047 | A            |            1 | TIT          |              61026341 |
|      17188477 | A            |            1 | TIT          | 100000000001214758912 |
|      45889412 | A            |            1 | TIT          |             364471119 |
|      33461559 | A            |            1 | TIT          |             263849518 |
|      21374256 | A            |            1 | TIT          |             233376659 |
|      27430960 | A            |            1 | TIT          |               6937497 |
|      37969104 | A            |            1 | TIT          |             166373908 |
|      37231452 | A            |            3 | TIT          |             283398926 |
|      37844698 | A            |            1 | TIT          |             177313050 |
|      44052613 | A            |            1 | TIT          |             318828504 |


Target Schema:
| FAP_CONTR   |   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 |   COD_INTERV |
|:------------|--------------:|---------------:|-----------:|---------------:|---------------:|-------------:|------------:|----------------:|------------:|----------:|----------:|-----------:|-----------:|-------------:|-------------:|---------------:|---------------:|---------------:|----------------:|-------------:|-------------:|-------------:|----------------:|-------------:|-------------:|-------------:|
| 01APR1984   |             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 |            1 |
| 01APR1986   |             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 |            1 |
| 01APR2004   |             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 |            3 |
| 01APR2005   |             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 |            2 |
| 01APR2008   |             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 |            1 |
| 01APR2009   |             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 |            1 |
| 01APR2010   |             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 |            1 |
| 01APR2014   |             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 |            1 |
| 01APR2015   |            28 |             28 |         28 |             28 |             28 |           28 |          28 |              28 |          28 |        28 |        28 |         28 |         28 |           28 |           28 |             28 |             28 |             28 |              28 |           28 |           28 |           28 |              28 |           28 |           28 |           28 |
| 01APR2016   |           368 |            368 |        368 |            368 |            368 |          368 |         368 |             368 |         368 |       367 |       367 |        368 |        368 |          368 |          368 |            368 |            368 |            368 |             368 |          368 |          368 |          368 |             368 |          367 |          368 |          368 |

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