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:
| Athlete          | Sport         |
|:-----------------|:--------------|
| Michael Phelps   | Swimming      |
| Natalie Coughlin | Swimming      |
| Aleksey Nemov    | Gymnastics    |
| Alicia Coutts    | Swimming      |
| Missy Franklin   | Swimming      |
| Ryan Lochte      | Swimming      |
| Allison Schmitt  | Swimming      |
| Ian Thorpe       | Swimming      |
| Dara Torres      | Swimming      |
| Cindy Klassen    | Speed Skating |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
| Athlete            |   Age |   Year | Closing Ceremony Date   |   Gold Medals |   Silver Medals |   Bronze Medals |   Total Medals |
|:-------------------|------:|-------:|:------------------------|--------------:|----------------:|----------------:|---------------:|
| Antero Niittymäki  |    25 |   2006 | 02/26/2006              |             0 |               1 |               0 |              1 |
| Fredrik Norrena    |    32 |   2006 | 02/26/2006              |             0 |               1 |               0 |              1 |
| Petteri Nummelin   |    33 |   2006 | 02/26/2006              |             0 |               1 |               0 |              1 |
| Teppo Numminen     |    37 |   2006 | 02/26/2006              |             0 |               1 |               0 |              1 |
| Emilie O'Konor     |    22 |   2006 | 02/26/2006              |             0 |               1 |               0 |              1 |
| Mattias Öhlund     |    29 |   2006 | 02/26/2006              |             1 |               0 |               0 |              1 |
| Rostislav Olesz    |    20 |   2006 | 02/26/2006              |             0 |               0 |               1 |              1 |
| Caroline Ouellette |    26 |   2006 | 02/26/2006              |             1 |               0 |               0 |              1 |
| Samuel Påhlsson    |    28 |   2006 | 02/26/2006              |             1 |               0 |               0 |              1 |
| Sarah Parsons      |    18 |   2006 | 02/26/2006              |             0 |               0 |               1 |              1 |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
| Athlete          | Country       |
|:-----------------|:--------------|
| Michael Phelps   | United States |
| Natalie Coughlin | United States |
| Aleksey Nemov    | Russia        |
| Alicia Coutts    | Australia     |
| Missy Franklin   | United States |
| Ryan Lochte      | United States |
| Allison Schmitt  | United States |
| Ian Thorpe       | Australia     |
| Dara Torres      | United States |
| Cindy Klassen    | Canada        |


Target Schema:
| Athlete          |   Age |   Year | Closing Ceremony Date   |   Gold Medals |   Silver Medals |   Bronze Medals |   Total Medals | Country       | Sport      |
|:-----------------|------:|-------:|:------------------------|--------------:|----------------:|----------------:|---------------:|:--------------|:-----------|
| Michael Phelps   |    23 |   2008 | 08/24/2008              |             8 |               0 |               0 |              8 | United States | Swimming   |
| Michael Phelps   |    19 |   2004 | 08/29/2004              |             6 |               0 |               2 |              8 | United States | Swimming   |
| Michael Phelps   |    27 |   2012 | 08/12/2012              |             4 |               2 |               0 |              6 | United States | Swimming   |
| Natalie Coughlin |    25 |   2008 | 08/24/2008              |             1 |               2 |               3 |              6 | United States | Swimming   |
| Natalie Coughlin |    21 |   2004 | 08/29/2004              |             2 |               2 |               1 |              5 | United States | Swimming   |
| Natalie Coughlin |    29 |   2012 | 08/12/2012              |             0 |               0 |               1 |              1 | United States | Swimming   |
| Aleksey Nemov    |    24 |   2000 | 10/01/2000              |             2 |               1 |               3 |              6 | Russia        | Gymnastics |
| Alicia Coutts    |    24 |   2012 | 08/12/2012              |             1 |               3 |               1 |              5 | Australia     | Swimming   |
| Missy Franklin   |    17 |   2012 | 08/12/2012              |             4 |               0 |               1 |              5 | United States | Swimming   |
| Ryan Lochte      |    27 |   2012 | 08/12/2012              |             2 |               2 |               1 |              5 | United States | Swimming   |

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