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:
|   ID Number | Name                       | Fed   | Sex   | Tit   | WTit   | OTit   | FOA   |   MAY20 |   Gms |   K |   B-day | Flag   |
|------------:|:---------------------------|:------|:------|:------|:-------|:-------|:------|--------:|------:|----:|--------:|:-------|
|    32043988 | Vila Vila, Ricard          | ESP   | M     |       |        |        |       |    1597 |     0 |  20 |    1960 |        |
|    22228390 | Pitarch Roca, Miguel Angel | ESP   | M     |       |        |        |       |    1868 |     0 |  20 |    1959 | i      |
|    14944529 | Pristas, Vincent           | SVK   | M     |       |        |        |       |    1406 |     0 |  20 |    1959 |        |
|     2205050 | Sanchez Marcos, Andres     | ESP   | M     |       |        |        |       |    1839 |     0 |  20 |    1979 |        |
|    13826158 | Povodyrev, Sergei          | KGZ   | M     |       |        |        |       |    1222 |     0 |  40 |    2010 |        |
|     2215071 | Molina Solis, Andres       | ESP   | M     |       |        |        |       |    2098 |     0 |  40 |    1928 | i      |
|    25603094 | Richa Mondal               | IND   | F     |       |        |        |       |    1006 |     0 |  40 |    2006 | wi     |
|      624314 | Makke, Laurent             | FRA   | M     |       |        |        |       |    2090 |     0 |  20 |    1986 |        |
|     2812584 | Triger, Ramon              | ISR   | M     |       |        |        |       |    2077 |     0 |  20 |    1999 | i      |
|    10224700 | Sabrina, Jahan Shejoti     | BAN   | F     |       |        |        |       |    1189 |     0 |  40 |    2010 | wi     |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|   ID Number | Name                       | Fed   | Sex   | Tit   | WTit   | OTit   | FOA   |   MAY20 |   Gms |   K |   B-day | Flag   |
|------------:|:---------------------------|:------|:------|:------|:-------|:-------|:------|--------:|------:|----:|--------:|:-------|
|    23718684 | Svoboda, Daniel            | CZE   | M     |       |        |        |       |    1422 |     0 |  20 |    2008 |        |
|      103373 | Moccero, Eduardo           | URU   | M     |       |        |        |       |    1925 |     0 |  20 |    1951 | i      |
|    20606095 | Rosello, Patrice           | FRA   | M     |       |        |        |       |    1627 |     0 |  20 |    1965 |        |
|    25838059 | Oikonomou, Dimitrios 43797 | GRE   | M     |       |        |        |       |    1396 |     0 |  20 |    1985 | i      |
|    34233431 | Shkurko, Leonid            | RUS   | M     |       |        |        |       |    1222 |     0 |  20 |    1949 |        |
|     3103510 | Ortiz Ocasio, Jose Antonio | PUR   | M     |       |        |        |       |    1670 |     0 |  20 |    1981 |        |
|     2501090 | Welsh, Michael             | IRL   | M     |       |        |        |       |    2016 |     0 |  20 |    1961 | i      |
|     2893679 | Aprile, Elisa              | ITA   | F     |       |        |        |       |    1085 |     0 |  20 |    2011 | w      |
|     4122356 | Jakovenko, Dmitry          | RUS   | M     | GM    |        |        |       |    2700 |     0 |  20 |    1983 |        |
|    22711872 | Muniz, Bernardo Cunha      | BRA   | M     |       |        |        |       |    1356 |     0 |  20 |    2009 | i      |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
|   ID Number | Name                        | Fed   | Sex   | Tit   | WTit   | OTit   | FOA   |   MAY20 |   Gms |   K |   B-day | Flag   |
|------------:|:----------------------------|:------|:------|:------|:-------|:-------|:------|--------:|------:|----:|--------:|:-------|
|     3951332 | Caterine Pizarro, Oscar Man | VEN   | M     |       |        |        |       |    1884 |     0 |  20 |    1973 | i      |
|     2809600 | Pasini, Nicolo              | ITA   | M     |       |        |        | AFM   |    2065 |     0 |  20 |    1996 |        |
|    34316329 | Gulenko, Zakhar             | RUS   | M     |       |        |        |       |    1239 |     0 |  20 |    2011 |        |
|    14649063 | Jerovsek, Alojz             | SLO   | M     |       |        |        |       |    1816 |     0 |  20 |    1954 |        |
|     1920421 | Santos, Jose Pinheiro Dos   | POR   | M     |       |        |        |       |    1390 |     0 |  20 |    1948 | i      |
|    22100504 | Bashota, Ekrem              | KOS   | M     |       |        |        |       |    2155 |     0 |  20 |    1974 |        |
|    44199422 | Kalmykov, Vladimir          | RUS   | M     |       |        |        |       |    1433 |     0 |  20 |    1999 | i      |
|    35010972 | Aruna Dinakara              | IND   | M     |       |        |        | AFM   |    1424 |     0 |  20 |    1986 | i      |
|    10103643 | Keto, Kinavuidi             | ANG   | M     |       |        |        |       |    1958 |     0 |  20 |    1974 | i      |
|     3907767 | Gomez Sanchez, Hector Jose  | VEN   | M     |       |        |        |       |    1845 |     0 |  20 |    1959 | i      |


Target Schema:
|   B-day |   ID Number |   Name_x |   Fed_x |   Sex_x |
|--------:|------------:|---------:|--------:|--------:|
|       0 |         738 |      738 |     738 |     738 |
|    1920 |           1 |        1 |       1 |       1 |
|    1922 |           1 |        1 |       1 |       1 |
|    1924 |           2 |        2 |       2 |       2 |
|    1925 |           2 |        2 |       2 |       2 |
|    1926 |           2 |        2 |       2 |       2 |
|    1927 |           1 |        1 |       1 |       1 |
|    1928 |           3 |        3 |       3 |       3 |
|    1929 |           6 |        6 |       6 |       6 |
|    1930 |          22 |       22 |      22 |      22 |

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
test: test_0.csv
test_1.csv
test_2.csv