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 |
|--------------:|:-------------|-------------:|:-------------|---------------:|
|      19475223 | A            |            1 | TIT          |      259151551 |
|      21342460 | A            |            1 | TIT          |        6422660 |
|      32559704 | A            |            1 | TIT          |      197162557 |
|      22412656 | A            |            3 | TIT          |        5457735 |
|      20194342 | A            |            2 | TIT          |        3110069 |
|      32826904 | A            |            1 | TIT          |      359421677 |
|      24055071 | A            |            1 | TIT          |      289974547 |
|      37236725 | A            |            1 | TIT          |      287402247 |
|      48447905 | A            |            1 | TIT          |      364968488 |
|      18643013 | A            |            1 | TIT          |       94653624 |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|   COD_IDCONTRA |   COD_PERSONA | FAP_CONTR   |   IMP_CAPDIS |   IMP_CAPINI |   IMP_CAPPEN |
|---------------:|--------------:|:------------|-------------:|-------------:|-------------:|
|      366177779 |      15574006 | 01DEC2016   |         0    |      1129    |       940.84 |
|      367465482 |      29260877 | 05JAN2017   |      6739.85 |      6739.85 |      6401.28 |
|      370155986 |       8913759 | 01FEB2017   |      4528.3  |      4528.3  |         0    |
|       25870352 |       6636137 | 24MAY1996   |     52588.6  |     52588.6  |         0    |
|      276917630 |      13661934 | 29MAR2016   |     28257.4  |     28257.4  |     25649.6  |
|      237710282 |      27970095 | 29MAY2014   |     62000    |     62000    |     59499.2  |
|      365228481 |      10257354 | 18NOV2016   |     15353.1  |     15353.1  |     14580.9  |
|      361595019 |       1248939 | 21OCT2016   |      3000    |      3000    |         0    |
|       16860604 |      25918036 | 15NOV2006   |    250963    |    107363    |    197505    |
|      280241100 |      30344086 | 23MAY2016   |      5168.88 |      5168.88 |      1358.13 |


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 |   COD_AREANEGO |   COD_EDAD |   COD_OFICIPAL |   COD_SEGLOBAL | estado_cli   |
|--------------:|---------------:|-----------:|---------------:|---------------:|:-------------|
|      35207771 |             13 |         83 |           1067 |             21 | A            |
|         63126 |             58 |         41 |           2410 |             35 | I            |
|      34639368 |             13 |         23 |           9059 |             12 | A            |
|      24697386 |             13 |         69 |           6431 |             22 | A            |
|      33400805 |             13 |         18 |             96 |             25 | A            |
|      35294940 |             13 |         65 |            947 |             23 | A            |
|      31320204 |             13 |         42 |           6493 |             24 | R            |
|      14494954 |             13 |         57 |            238 |             22 | A            |
|      34011958 |             13 |         57 |           9695 |             24 | A            |
|      28210711 |             13 |         35 |            552 |             24 | M            |


Target Schema:
| COD_INTERV   | estado_cli   |   COD_EDAD |   COD_OFICIPAL |   COD_SEGLOBAL |
|:-------------|:-------------|-----------:|---------------:|---------------:|
| ASE          | A            |        152 |            152 |            152 |
| BEN          | A            |          8 |              8 |              8 |
| GAR          | A            |        164 |            164 |            164 |
| GRE          | A            |          2 |              2 |              2 |
| PAU          | A            |        147 |            147 |            147 |
| REP          | A            |         98 |             98 |             98 |
| TIT          | A            |      15417 |          15417 |          15417 |
| TIT          | I            |          5 |              5 |              5 |
| USU          | A            |          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