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:
|   WarNum |   WhereFought |
|---------:|--------------:|
|        1 |             2 |
|        1 |             2 |
|        4 |            11 |
|        4 |            11 |
|        7 |             1 |
|        7 |             1 |
|       10 |             2 |
|       10 |             2 |
|       10 |             2 |
|       10 |             2 |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|   WarNum |   WhereFought |
|---------:|--------------:|
|      751 |             7 |
|      751 |             7 |
|      752 |             6 |
|      753 |             6 |
|      755 |             6 |
|      755 |             6 |
|      756 |             7 |
|      756 |             7 |
|      756 |             7 |
|      757 |             4 |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
|   WarNum |   WhereFought |
|---------:|--------------:|
|      300 |             6 |
|      300 |             6 |
|      301 |             6 |
|      302 |             1 |
|      303 |             1 |
|      304 |             1 |
|      305 |             7 |
|      306 |             7 |
|      307 |             4 |
|      308 |             1 |


Table #4
Filename: source_3.csv
Sample Rows in Markdown:
|   WarNum |   WhereFought |
|---------:|--------------:|
|     1500 |             9 |
|     1501 |             4 |
|     1502 |             7 |
|     1503 |             1 |
|     1505 |             9 |
|     1506 |             7 |
|     1508 |             7 |
|     1509 |             1 |
|     1510 |             1 |
|     1511 |             7 |


Target Schema:
|   WarNum |   WhereFought |
|---------:|--------------:|
|        1 |             2 |
|        4 |             2 |
|        7 |             2 |
|       10 |             4 |
|       13 |             2 |
|       16 |             4 |
|       19 |             2 |
|       22 |             5 |
|       25 |             2 |
|       28 |             3 |

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