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 |
|--------------:|:-------------|-------------:|:-------------|----------------------:|
|      34263832 | A            |            1 | TIT          |             188966323 |
|      45575854 | A            |            1 | TIT          |             335844253 |
|      31493464 | A            |            2 | TIT          | 100000000001302478848 |
|      17050938 | A            |            1 | TIT          |              66366104 |
|      20219578 | A            |            1 | TIT          |               6884053 |
|      23736707 | C            |            2 | TIT          |              19234907 |
|      33376379 | A            |            1 | REP          |             257225622 |
|      19906939 | A            |            1 | TIT          |             256246600 |
|      25458401 | A            |            1 | TIT          |             151852627 |
|      25010617 | A            |            1 | TIT          | 100000000000645218304 |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|   COD_PERSONA |   COD_AREANEGO |   COD_EDAD |   COD_OFICIPAL |   COD_SEGLOBAL | estado_cli   |
|--------------:|---------------:|-----------:|---------------:|---------------:|:-------------|
|      31438908 |           6057 |         42 |           9981 |             24 | I            |
|      14058347 |             13 |         39 |           5971 |             22 | A            |
|      28386810 |             13 |         53 |           3209 |             24 | A            |
|      22663675 |             13 |         28 |           3486 |             25 | A            |
|       3540617 |             13 |         67 |           4016 |             23 | A            |
|      11555135 |             13 |         36 |           1914 |             24 | A            |
|       6901143 |             13 |         48 |           3502 |             24 | A            |
|      40360654 |             13 |         66 |            403 |             23 | A            |
|      33290423 |           6057 |         30 |           8248 |             24 | I            |
|        237037 |           6057 |         57 |           8248 |             24 | I            |


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_IDCONTRA |   COD_PERSONA | FAP_CONTR   |   IMP_CAPDIS |   IMP_CAPINI |   IMP_CAPPEN |
|----------------------:|--------------:|:------------|-------------:|-------------:|-------------:|
|             280732286 |       6651965 | 31MAY2016   |            0 |         0    |         0    |
|             363780953 |      19166041 | 31OCT2016   |            0 |         0    |         0    |
|             264480508 |      19460850 | 25SEP2015   |            0 |         0    |         0    |
|             359235673 |      15898997 | 30AUG2016   |            0 |         0    |         0    |
|             358071079 |      17100114 | 03AUG2016   |            0 |       461.03 |         0    |
|             368410402 |      18447343 | 09JAN2017   |            0 |       300    |       287.02 |
|              20339597 |      16085778 | 12JUN2006   |       162000 |    162000    |    121633    |
|              18335852 |       8414297 | 23OCT2006   |         2800 |      2800    |         0    |
|             271829386 |       7131690 | 31DEC2015   |            0 |         0    |         0    |
| 100000000000597180416 |        118488 | 22MAR2017   |         9478 |      9478    |      9478    |


Target Schema:
| COD_INTERV   | estado_cli   |   COD_PERSONA |   COD_AREANEGO |   COD_EDAD |
|:-------------|:-------------|--------------:|---------------:|-----------:|
| 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