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 |   COD_AREANEGO |   COD_EDAD |   COD_OFICIPAL |   COD_SEGLOBAL | estado_cli   |
|--------------:|---------------:|-----------:|---------------:|---------------:|:-------------|
|      33055293 |           6057 |         38 |           8630 |             24 | A            |
|       8921320 |             13 |         48 |           6100 |             24 | A            |
|       2864394 |             13 |         59 |           6404 |             24 | A            |
|       5293759 |             13 |         59 |           1605 |             23 | A            |
|       5609549 |             13 |         53 |           9434 |             15 | I            |
|      13241770 |             13 |         55 |           9303 |             24 | I            |
|      13090818 |             13 |         51 |           6665 |             24 | A            |
|       2175649 |             13 |         79 |           4607 |             22 | A            |
|      20429374 |             16 |         37 |           6054 |             24 | A            |
|      45331907 |             13 |         53 |           8671 |             24 | A            |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
|          COD_IDCONTRA |   COD_PERSONA | FAP_CONTR   |   IMP_CAPDIS |   IMP_CAPINI |   IMP_CAPPEN |
|----------------------:|--------------:|:------------|-------------:|-------------:|-------------:|
|              19848136 |       8792226 | 08OCT1998   |        83687 |     51687    |     15665.9  |
|             264405599 |      29754533 | 30SEP2015   |        10000 |     10000    |      7604.98 |
|             188206526 |      25171635 | 20JUN2013   |        87067 |     87067    |         0    |
| 100000000000683622400 |      22861879 | 21DEC2012   |       166454 |    166454    |    124749    |
|              82373600 |      26589108 | 06MAR2017   |            0 |       242.27 |       242.27 |
|             272265353 |       8056550 | 11JAN2016   |            0 |         0    |         0    |
|             283536123 |      35069589 | 30NOV2006   |        70000 |     70000    |     31277.5  |
|             358071562 |      18766316 | 03AUG2016   |            0 |      1500    |       783.46 |
|             356107552 |       9554241 | 04JUL2016   |            0 |         0    |         0    |
|             359232062 |      14228563 | 30AUG2016   |        25000 |     25000    |         0    |


Table #4
Filename: source_3.csv
Sample Rows in Markdown:
|   COD_PERSONA | XTI_ESTADO   |   QNU_ORDTIT | COD_INTERV   |          COD_IDCONTRA |
|--------------:|:-------------|-------------:|:-------------|----------------------:|
|      32886733 | A            |            1 | TIT          |              98022212 |
|      20915353 | A            |            1 | TIT          |               6876832 |
|      22042068 | A            |            2 | TIT          |              79532294 |
|      43510507 | I            |            1 | TIT          |             318753438 |
|      20508919 | I            |            1 | TIT          |              37271709 |
|      27471616 | C            |            1 | TIT          |             293693872 |
|      16612663 | A            |            1 | TIT          |             249460722 |
|      30965281 | A            |            1 | TIT          | 100000000001308737536 |
|      28437698 | A            |            1 | TIT          |             260810643 |
|      37842665 | C            |            1 | TIT          |             196662360 |


Target Schema:
| COD_INTERV   | FAP_CONTR   | 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 |   IMP_CAPDIS |   IMP_CAPINI |   IMP_CAPPEN |   COD_PERSONA_y |   XTI_ESTADO |   QNU_ORDTIT |
|:-------------|:------------|:-------------|--------------:|---------------:|-----------:|---------------:|---------------:|------------:|----------------:|------------:|----------:|----------:|-----------:|-----------:|-------------:|-------------:|---------------:|---------------:|---------------:|----------------:|-------------:|-------------:|-------------:|----------------:|-------------:|-------------:|
| ASE          | 02MAR2015   | A            |            13 |             13 |         13 |             13 |             13 |          13 |              13 |          13 |        13 |        13 |         13 |         13 |           13 |           13 |             13 |             13 |             13 |              13 |           13 |           13 |           13 |              13 |           13 |           13 |
| ASE          | 03MAR2015   | A            |            13 |             13 |         13 |             13 |             13 |          13 |              13 |          13 |        13 |        13 |         13 |         13 |           13 |           13 |             13 |             13 |             13 |              13 |           13 |           13 |           13 |              13 |           13 |           13 |
| ASE          | 04MAR2015   | A            |             3 |              3 |          3 |              3 |              3 |           3 |               3 |           3 |         3 |         3 |          3 |          3 |            3 |            3 |              3 |              3 |              3 |               3 |            3 |            3 |            3 |               3 |            3 |            3 |
| ASE          | 04NOV2015   | 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 |
| ASE          | 05MAR2015   | 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 |
| ASE          | 06MAR2015   | A            |             7 |              7 |          7 |              7 |              7 |           7 |               7 |           7 |         7 |         7 |          7 |          7 |            7 |            7 |              7 |              7 |              7 |               7 |            7 |            7 |            7 |               7 |            7 |            7 |
| ASE          | 09MAR2015   | 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 |
| ASE          | 10APR2015   | 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 |
| ASE          | 10FEB2015   | 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 |
| ASE          | 10MAR2015   | A            |             5 |              5 |          5 |              5 |              5 |           5 |               5 |           5 |         5 |         5 |          5 |          5 |            5 |            5 |              5 |              5 |              5 |               5 |            5 |            5 |            5 |               5 |            5 |            5 |

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