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_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 #2
Filename: source_1.csv
Sample Rows in Markdown:
|   COD_PERSONA | XTI_ESTADO   |   QNU_ORDTIT | COD_INTERV   |          COD_IDCONTRA |
|--------------:|:-------------|-------------:|:-------------|----------------------:|
|      45570181 | A            |            2 | TIT          |             298658694 |
|      30879261 | C            |            1 | GAR          |             364195837 |
|      24527383 | A            |            1 | TIT          | 100000000001222131712 |
|      43510327 | I            |            1 | TIT          |             289163774 |
|      27993494 | A            |            1 | TIT          |              21627484 |
|      40200932 |              |            1 | GAR          |             358045555 |
|      18139354 | I            |            1 | TIT          |             263341800 |
|      37865262 | A            |            1 | TIT          |             189121021 |
|      40102540 | A            |            1 | TIT          | 100000000001220558848 |
|      35015791 | C            |            1 | TIT          |             277624735 |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
|   COD_PERSONA |   COD_AREANEGO |   COD_EDAD |   COD_OFICIPAL |   COD_SEGLOBAL | estado_cli   |
|--------------:|---------------:|-----------:|---------------:|---------------:|:-------------|
|      40223618 |             13 |         46 |           1870 |             24 | I            |
|       9046181 |             13 |         55 |           1344 |             21 | A            |
|        959674 |           6057 |         76 |           9487 |             23 | A            |
|      25029303 |             13 |         39 |            520 |             24 | A            |
|      30241726 |           6057 |         51 |           3391 |             83 | I            |
|      24233463 |             13 |         38 |           1443 |             24 | A            |
|      13388496 |             13 |         45 |           8163 |             24 | A            |
|      15286046 |             13 |         69 |           2200 |             14 | A            |
|       2303602 |           6057 |         67 |            807 |             23 | A            |
|      37768775 |             13 |         58 |           8766 |             89 | A            |


Table #4
Filename: source_3.csv
Sample Rows in Markdown:
|   COD_IDCONTRA |   COD_PERSONA | FAP_CONTR   |   IMP_CAPDIS |   IMP_CAPINI |   IMP_CAPPEN |
|---------------:|--------------:|:------------|-------------:|-------------:|-------------:|
|      367277072 |      18401479 | 19DEC2016   |          0   |         20   |         0    |
|      271516875 |       3038200 | 24DEC2015   |          0   |          0   |         0    |
|      264996203 |       6620274 | 01OCT2015   |          0   |          0   |         0    |
|      358872429 |        294128 | 10JUL2007   |          0   |     200002   |    184450    |
|      275136033 |      40130120 | 18APR2016   |     135421   |     135421   |    131501    |
|      246255690 |      28242431 | 05NOV2014   |      10763.5 |      10763.5 |      6335.69 |
|      372476874 |      18401479 | 06MAR2017   |          0   |         80   |        80    |
|       19093557 |      11011170 | 18JUN2008   |     295000   |     295000   |    172487    |
|      264237364 |       1372902 | 22SEP2015   |          0   |          0   |         0    |
|      280654661 |        381056 | 30MAY2016   |          0   |          0   |         0    |


Target Schema:
| COD_INTERV   | estado_cli   |   COD_PERSONA |   COD_AREANEGO |   COD_EDAD |   COD_OFICIPAL |   COD_SEGLOBAL |   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 |   FAP_CONTR |   IMP_CAPDIS |   IMP_CAPINI |   IMP_CAPPEN |   COD_PERSONA_y |   XTI_ESTADO |   QNU_ORDTIT |
|:-------------|:-------------|--------------:|---------------:|-----------:|---------------:|---------------:|------------:|----------------:|------------:|----------:|----------:|-----------:|-----------:|-------------:|-------------:|---------------:|---------------:|---------------:|----------------:|------------:|-------------:|-------------:|-------------:|----------------:|-------------:|-------------:|
| ASE          | A            |           152 |            152 |        152 |            152 |            152 |         152 |             152 |         152 |       152 |       152 |        152 |        152 |          152 |          152 |            152 |            152 |            152 |             152 |         152 |          152 |          152 |          152 |             152 |          152 |          152 |
| BEN          | A            |             8 |              8 |          8 |              8 |              8 |           8 |               8 |           8 |         8 |         8 |          8 |          8 |            8 |            8 |              8 |              8 |              8 |               8 |           8 |            8 |            8 |            8 |               8 |            8 |            8 |
| GAR          | A            |           164 |            164 |        164 |            164 |            164 |         164 |             164 |         164 |       164 |       164 |        164 |        164 |          164 |          164 |            164 |            164 |            164 |             164 |         164 |          164 |          164 |          164 |             164 |          158 |          164 |
| GRE          | A            |             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 |
| PAU          | A            |           147 |            147 |        147 |            147 |            147 |         147 |             147 |         147 |       146 |       146 |        147 |        147 |          147 |          147 |            147 |            147 |            147 |             147 |         147 |          147 |          147 |          147 |             147 |          147 |          147 |
| REP          | A            |            98 |             98 |         98 |             98 |             98 |          98 |              98 |          98 |        98 |        98 |         98 |         98 |           98 |           98 |             98 |             98 |             98 |              98 |          98 |           98 |           98 |           98 |              98 |           93 |           98 |
| TIT          | A            |         15417 |          15417 |      15417 |          15417 |          15417 |       15417 |           15417 |       15417 |     15370 |     15370 |      15417 |      15417 |        15417 |        15417 |          15417 |          15417 |          15417 |           15417 |       15417 |        15417 |        15417 |        15417 |           15417 |        14919 |        15417 |
| TIT          | I            |             5 |              5 |          5 |              5 |              5 |           5 |               5 |           5 |         5 |         5 |          5 |          5 |            5 |            5 |              5 |              5 |              5 |               5 |           5 |            5 |            5 |            5 |               5 |            5 |            5 |
| USU          | A            |             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