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_IDCONTRA |   COD_PERSONA | FAP_CONTR   |   IMP_CAPDIS |   IMP_CAPINI |   IMP_CAPPEN |
|---------------:|--------------:|:------------|-------------:|-------------:|-------------:|
|      269938930 |      18401479 | 09DEC2015   |          0   |         0    |         0    |
|      275847554 |       7885259 | 08MAR2016   |          0   |         0    |         0    |
|      267822816 |      19139666 | 17NOV2015   |      12800   |     12800    |     10479.3  |
|      259151551 |      19475223 | 23JUN2015   |      13021.2 |     13021.2  |      7893.32 |
|      283741614 |      45249778 | 15FEB2008   |     184922   |    184922    |    137913    |
|      372881911 |      25341729 | 10MAR2017   |          0   |        67.37 |        67.37 |
|      263327329 |      37865666 | 04SEP2015   |          0   |         0    |         0    |
|      370431475 |       9679642 | 06FEB2017   |       2500   |      2500    |      2441.12 |
|      357932464 |      27960318 | 01AUG2016   |          0   |         0    |         0    |
|      276091813 |      14022511 | 28APR2016   |     108586   |    108586    |    103182    |


Table #2
Filename: source_1.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 #3
Filename: source_2.csv
Sample Rows in Markdown:
|   COD_PERSONA |   COD_AREANEGO |   COD_EDAD |   COD_OFICIPAL |   COD_SEGLOBAL | estado_cli   |
|--------------:|---------------:|-----------:|---------------:|---------------:|:-------------|
|      45073418 |             13 |         23 |           4332 |             25 | A            |
|       1565509 |             13 |         61 |           4388 |             23 | A            |
|       3427975 |             13 |         62 |           1497 |             83 | M            |
|      45636001 |             13 |         18 |           2972 |             25 | A            |
|      34197120 |           6057 |         49 |           2956 |             24 | A            |
|      35465787 |           6057 |         52 |           9981 |             24 | I            |
|       5175798 |             13 |         60 |           1440 |             83 | M            |
|       3420635 |           6057 |         40 |           8248 |             24 | I            |
|      17258960 |             13 |         51 |           1278 |             24 | A            |
|       3893056 |             13 |         73 |            594 |             14 | A            |


Table #4
Filename: source_3.csv
Sample Rows in Markdown:
|   COD_PERSONA | XTI_ESTADO   |   QNU_ORDTIT | COD_INTERV   |          COD_IDCONTRA |
|--------------:|:-------------|-------------:|:-------------|----------------------:|
|      33635201 | A            |            1 | TIT          |             365107803 |
|      17464608 | A            |            1 | REP          |               3824437 |
|      42141013 | A            |            1 | TIT          |             317073670 |
|      22857980 | A            |            1 | TIT          |              20970803 |
|      28980583 | I            |            1 | TIT          |             356625368 |
|      32138930 | A            |            1 | TIT          |             252211541 |
|      28363892 | A            |            1 | TIT          |             212861896 |
|      45127736 | A            |            1 | TIT          | 100000000001306804224 |
|      32713230 | A            |            1 | REP          | 100000000001303134208 |
|      19771885 | C            |            1 | TIT          | 100000000000507969536 |


Target Schema:
| COD_INTERV   |   COD_PERSONA |   COD_AREANEGO |   COD_EDAD |   COD_OFICIPAL |   COD_SEGLOBAL |   estado_cli |   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          |           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 |          152 |
| BEN          |             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 |            8 |
| GAR          |           164 |            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          |             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 |            2 |
| PAU          |           147 |            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          |            98 |             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          |         15422 |          15422 |      15422 |          15422 |          15422 |        15422 |       15422 |           15422 |       15422 |     15375 |     15375 |      15422 |      15422 |        15422 |        15422 |          15422 |          15422 |          15422 |           15422 |       15422 |        15422 |        15422 |        15422 |           15422 |        14924 |        15422 |
| USU          |             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 |            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