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:
|   WarID | PolityID   | PolityName               |   StartYear | StartMonth   | StartDay   |   EndYear | EndMonth   | EndDay   | Side   |   IsInitiator |   Outcome | Deaths   |
|--------:|:-----------|:-------------------------|------------:|:-------------|:-----------|----------:|:-----------|:---------|:-------|--------------:|----------:|:---------|
|    1500 |            | Te Rauparaha's Ngati Toa |        1818 |              |            |      1824 |            |          | A      |             1 |         1 | 1500.0   |
|    1500 |            | Ngati Ira                |        1818 |              |            |      1824 |            |          | B      |             0 |         2 | 6000.0   |
|    1500 |            | Waikato                  |        1818 |              |            |      1824 |            |          | B      |             0 |         2 | 6000.0   |
|    1500 |            | Ngai Tahu                |        1818 |              |            |      1824 |            |          | B      |             0 |         2 | 6000.0   |
|    1500 |            | Taranaki                 |        1818 |              |            |      1824 |            |          | B      |             0 |         2 | 6000.0   |
|    1500 |            | Rangitikei               |        1818 |              |            |      1824 |            |          | B      |             0 |         2 | 6000.0   |
|    1501 |            | Shaka Zulu               |        1819 |              |            |      1828 | 9.0        | 24.0     | A      |             1 |         1 | 20000.0  |
|    1501 |            | Bantu                    |        1819 |              |            |      1828 | 9.0        | 24.0     | B      |             0 |         2 | 40000.0  |
|    1502 |            | Burma                    |        1819 |              |            |      1822 |            |          | A      |             1 |         1 |          |
|    1502 |            | Assam                    |        1819 |              |            |      1822 |            |          | B      |             0 |         2 |          |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|   WarID | PolityID   | PolityName               |   StartYear |   StartMonth | StartDay   |   EndYear |   EndMonth | EndDay   | Side   |   IsInitiator |   Outcome | Deaths   |
|--------:|:-----------|:-------------------------|------------:|-------------:|:-----------|----------:|-----------:|:---------|:-------|--------------:|----------:|:---------|
|     741 | 710.0      | China                    |        1956 |            3 | 1.0        |      1959 |          4 | 14.0     | A      |             0 |         1 | 4000.0   |
|     742 |            | Leftists                 |        1956 |           12 | 15.0       |      1962 |          6 | 4.0      | B      |             1 |         2 | 23500.0  |
|     742 | 850.0      | Indonesia                |        1956 |           12 | 15.0       |      1962 |          6 | 4.0      | A      |             0 |         1 | 3700.0   |
|     743 | 2.0        | United States of America |        1958 |            7 | 16.0       |      1958 |          9 | 15.0     | A      |             0 |         1 | 1.0      |
|     743 |            | National Front           |        1958 |            5 | 9.0        |      1958 |          9 | 15.0     | B      |             1 |         2 |          |
|     743 | 660.0      | Lebanon                  |        1958 |            5 | 9.0        |      1958 |          9 | 15.0     | A      |             0 |         1 |          |
|     745 |            | Castroites               |        1958 |            5 | 24.0       |      1959 |          1 | 2.0      | B      |             1 |         1 | 1000.0   |
|     745 | 40.0       | Cuba                     |        1958 |            5 | 24.0       |      1959 |          1 | 2.0      | A      |             0 |         2 | 2000.0   |
|     746 | 775.0      | Burma                    |        1958 |           11 |            |      1960 |          4 |          | A      |             0 |         7 | 850.0    |
|     746 |            | Karens & Communists      |        1958 |           11 |            |      1960 |          4 |          | B      |             1 |         7 | 2300.0   |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
|   WarID |   PolityID | PolityName     |   StartYear | StartMonth   | StartDay   |   EndYear |   EndMonth | EndDay   | Side   |   IsInitiator |   Outcome |   Deaths |
|--------:|-----------:|:---------------|------------:|:-------------|:-----------|----------:|-----------:|:---------|:-------|--------------:|----------:|---------:|
|     300 |        210 | Netherlands    |        1816 | 8.0          | 26.0       |      1816 |          8 | 30.0     | A      |             1 |         1 |       13 |
|     300 |        200 | United Kingdom |        1816 | 8.0          | 26.0       |      1816 |          8 | 30.0     | A      |             1 |         1 |      129 |
|     301 |        640 | Ottoman Empire |        1816 | 9.0          |            |      1818 |          9 | 11.0     | A      |             1 |         1 |    13500 |
|     302 |        230 | Spain          |        1817 | 1.0          | 9.0        |      1818 |          4 | 5.0      | A      |             0 |         2 |     1700 |
|     303 |        230 | Spain          |        1817 | 4.0          | 11.0       |      1819 |          8 | 10.0     | A      |             1 |         2 |     3000 |
|     304 |        230 | Spain          |        1817 | 8.0          | 15.0       |      1818 |          1 | 1.0      | A      |             0 |         1 |     1000 |
|     305 |        200 | United Kingdom |        1817 | 10.0         |            |      1818 |         11 | 26.0     | A      |             0 |         1 |     1000 |
|     306 |        200 | United Kingdom |        1817 | 11.0         | 6.0        |      1818 |          6 | 3.0      | A      |             0 |         1 |     2800 |
|     307 |        640 | Ottoman Empire |        1820 |              |            |      1821 |          6 |          | A      |             1 |         1 |     4000 |
|     308 |        230 | Spain          |        1821 | 4.0          | 28.0       |      1822 |          5 | 24.0     | A      |             0 |         2 |     1000 |


Table #4
Filename: source_3.csv
Sample Rows in Markdown:
|   WarID |   PolityID |   StartYear |   StartMonth |   StartDay |   EndYear |   EndMonth |   EndDay | Side   |   IsInitiator |   Outcome |   Deaths |
|--------:|-----------:|------------:|-------------:|-----------:|----------:|-----------:|---------:|:-------|--------------:|----------:|---------:|
|       1 |        230 |        1823 |            4 |          7 |      1823 |         11 |       13 | B      |             0 |         2 |      600 |
|       1 |        220 |        1823 |            4 |          7 |      1823 |         11 |       13 | A      |             1 |         1 |      400 |
|       4 |        640 |        1828 |            4 |         26 |      1829 |          9 |       14 | B      |             0 |         2 |    80000 |
|       4 |        365 |        1828 |            4 |         26 |      1829 |          9 |       14 | A      |             1 |         1 |    50000 |
|       7 |         70 |        1846 |            4 |         25 |      1847 |          9 |       14 | B      |             0 |         2 |     6000 |
|       7 |          2 |        1846 |            4 |         25 |      1847 |          9 |       14 | A      |             1 |         1 |    13283 |
|      10 |        337 |        1848 |            3 |         29 |      1848 |          8 |        9 | B      |             0 |         2 |      100 |
|      10 |        325 |        1848 |            3 |         24 |      1848 |          8 |        9 | B      |             1 |         2 |     3400 |
|      10 |        300 |        1848 |            3 |         24 |      1848 |          8 |        9 | A      |             0 |         1 |     3927 |
|      10 |        332 |        1848 |            4 |          9 |      1848 |          8 |        9 | B      |             0 |         2 |      100 |


Target Schema:
|   IsInitiator |   WarID |   PolityID |   StartYear |   StartMonth |   StartDay |   EndYear |   EndMonth |   EndDay |   Side |   Outcome |   Deaths |   PolityName |
|--------------:|--------:|-----------:|------------:|-------------:|-----------:|----------:|-----------:|---------:|-------:|----------:|---------:|-------------:|
|             0 |     716 |        537 |         716 |          678 |        605 |       711 |        670 |      621 |    716 |       716 |      573 |          475 |
|             1 |     549 |        218 |         549 |          515 |        451 |       539 |        506 |      457 |    549 |       549 |      409 |          434 |

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