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 |
|--------------:|:-------------|-------------:|:-------------|----------------------:|
|      16896129 | A            |            1 | TIT          |              65282775 |
|      15937191 | I            |            1 | TIT          |             242587739 |
|      28884608 | A            |            1 | TIT          |              19731599 |
|      27457943 | A            |            1 | TIT          |             268589816 |
|      18006918 | A            |            1 | TIT          |             148146575 |
|      44501099 | A            |            2 | TIT          |             312978882 |
|      19583025 | A            |            1 | TIT          |              16598253 |
|      37676389 | A            |            1 | TIT          | 100000000001194491904 |
|      19165425 | A            |            1 | TIT          | 100000000001327955968 |
|      23650183 | A            |            1 | TIT          | 100000000000477757440 |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|   COD_IDCONTRA |   COD_PERSONA | FAP_CONTR   |   IMP_CAPDIS |   IMP_CAPINI |   IMP_CAPPEN |
|---------------:|--------------:|:------------|-------------:|-------------:|-------------:|
|      266600143 |      37811885 | 26OCT2015   |            0 |         0    |         0    |
|      368302331 |       8241135 | 05JAN2017   |            0 |       123.79 |        41.27 |
|       21118261 |      26485332 | 26JAN2007   |        88000 |     88000    |     73861.5  |
|      159618656 |      23477902 | 19DEC2012   |        68400 |     68400    |     43151.1  |
|       18893954 |      26474792 | 01FEB2007   |       130062 |    130062    |    114810    |
|      370784759 |       9874530 | 09FEB2017   |            0 |       204.7  |       204.7  |
|      358379686 |      18401479 | 10AUG2016   |            0 |         0    |         0    |
|       20077121 |      20906894 | 28FEB2001   |        88499 |     88499    |     16926.8  |
|      161085618 |      25121620 | 28NOV2016   |            0 |         0    |         0    |
|      258400580 |      26326854 | 08JUL2015   |         2570 |      2570    |         0    |


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   |
|--------------:|---------------:|-----------:|---------------:|---------------:|:-------------|
|      26167443 |           6057 |         33 |           9613 |             24 | I            |
|      18886445 |             13 |         33 |           2742 |             24 | A            |
|      33274619 |             13 |         24 |           1418 |             25 | A            |
|      29801202 |             13 |         84 |           2816 |             23 | A            |
|      33038498 |           6057 |         26 |           8642 |             25 | A            |
|      17424933 |             13 |         19 |           2212 |             25 | A            |
|       7265922 |             13 |         63 |           9465 |             23 | A            |
|       8112635 |             13 |         47 |           8320 |             24 | I            |
|      21809664 |             58 |         33 |            170 |             24 | I            |
|      11821659 |             88 |         47 |           6228 |              9 | A            |


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