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 | PolityName   |   StartYear | StartMonth   | StartDay   |   EndYear | EndMonth   | EndDay   | Initiator   |   Outcome | Deaths   |
|--------:|:-------------|------------:|:-------------|:-----------|----------:|:-----------|:---------|:------------|----------:|:---------|
|    1500 | Ngai Tahu    |        1818 |              |            |      1824 |            |          | A           |         1 | 6000.0   |
|    1501 |              |        1819 |              |            |      1828 | 9.0        | 24.0     | A           |         1 | 40000.0  |
|    1502 |              |        1819 |              |            |      1822 |            |          | A           |         1 |          |
|    1503 |              |        1820 | 1.0          | 8.0        |      1820 | 2.0        | 23.0     | B           |         2 |          |
|    1505 | Ngati Maru   |        1821 | 9.0          |            |      1823 |            |          | A           |         1 | 2000.0   |
|    1506 |              |        1821 | 11.0         |            |      1821 | 12.0       |          | A           |         1 |          |
|    1508 |              |        1825 |              |            |      1828 |            |          | A           |         1 |          |
|    1509 |              |        1825 | 10.0         | 25.0       |      1827 | 4.0        | 13.0     | A           |         3 |          |
|    1510 |              |        1826 |              |            |      1829 | 4.0        | 12.0     | B           |         2 | 1300.0   |
|    1511 |              |        1826 |              |            |      1827 | 5.0        | 15.0     | A           |         2 | 7000.0   |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|   WarID | PolityName          |   StartYear | StartMonth   | StartDay   |   EndYear | EndMonth   | EndDay   | Initiator   |   Outcome | Deaths   |
|--------:|:--------------------|------------:|:-------------|:-----------|----------:|:-----------|:---------|:------------|----------:|:---------|
|    1500 | Waikato             |        1818 |              |            |      1824 |            |          | A           |         1 | 6000.0   |
|    1501 |                     |        1819 |              |            |      1828 | 9.0        | 24.0     | A           |         1 | 40000.0  |
|    1502 |                     |        1819 |              |            |      1822 |            |          | A           |         1 |          |
|    1503 |                     |        1820 | 1.0          | 8.0        |      1820 | 2.0        | 23.0     | B           |         2 |          |
|    1505 | Waikato River Maori |        1821 | 9.0          |            |      1823 |            |          | A           |         1 | 2000.0   |
|    1506 |                     |        1821 | 11.0         |            |      1821 | 12.0       |          | A           |         1 |          |
|    1508 |                     |        1825 |              |            |      1828 |            |          | A           |         1 |          |
|    1509 |                     |        1825 | 10.0         | 25.0       |      1827 | 4.0        | 13.0     | A           |         3 |          |
|    1510 |                     |        1826 |              |            |      1829 | 4.0        | 12.0     | B           |         2 | 1300.0   |
|    1511 |                     |        1826 |              |            |      1827 | 5.0        | 15.0     | A           |         2 | 7000.0   |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
|   WarID | PolityName   |   StartYear | StartMonth   | StartDay   |   EndYear | EndMonth   | EndDay   | Initiator   |   Outcome | Deaths   |
|--------:|:-------------|------------:|:-------------|:-----------|----------:|:-----------|:---------|:------------|----------:|:---------|
|    1500 | Rangitikei   |        1818 |              |            |      1824 |            |          | A           |         1 | 6000.0   |
|    1501 |              |        1819 |              |            |      1828 | 9.0        | 24.0     | A           |         1 | 40000.0  |
|    1502 |              |        1819 |              |            |      1822 |            |          | A           |         1 |          |
|    1503 |              |        1820 | 1.0          | 8.0        |      1820 | 2.0        | 23.0     | B           |         2 |          |
|    1505 |              |        1821 | 9.0          |            |      1823 |            |          | A           |         1 | 2000.0   |
|    1506 |              |        1821 | 11.0         |            |      1821 | 12.0       |          | A           |         1 |          |
|    1508 |              |        1825 |              |            |      1828 |            |          | A           |         1 |          |
|    1509 |              |        1825 | 10.0         | 25.0       |      1827 | 4.0        | 13.0     | A           |         3 |          |
|    1510 |              |        1826 |              |            |      1829 | 4.0        | 12.0     | B           |         2 | 1300.0   |
|    1511 |              |        1826 |              |            |      1827 | 5.0        | 15.0     | A           |         2 | 7000.0   |


Table #4
Filename: source_3.csv
Sample Rows in Markdown:
|   WarID | PolityName   |   StartYear | StartMonth   | StartDay   |   EndYear | EndMonth   | EndDay   | Initiator   |   Outcome | Deaths   |
|--------:|:-------------|------------:|:-------------|:-----------|----------:|:-----------|:---------|:------------|----------:|:---------|
|    1500 | Ngati Ira    |        1818 |              |            |      1824 |            |          | A           |         1 | 6000.0   |
|    1501 |              |        1819 |              |            |      1828 | 9.0        | 24.0     | A           |         1 | 40000.0  |
|    1502 |              |        1819 |              |            |      1822 |            |          | A           |         1 |          |
|    1503 |              |        1820 | 1.0          | 8.0        |      1820 | 2.0        | 23.0     | B           |         2 |          |
|    1505 | Te Arawa     |        1821 | 9.0          |            |      1823 |            |          | A           |         1 | 2000.0   |
|    1506 |              |        1821 | 11.0         |            |      1821 | 12.0       |          | A           |         1 |          |
|    1508 |              |        1825 |              |            |      1828 |            |          | A           |         1 |          |
|    1509 |              |        1825 | 10.0         | 25.0       |      1827 | 4.0        | 13.0     | A           |         3 |          |
|    1510 |              |        1826 |              |            |      1829 | 4.0        | 12.0     | B           |         2 | 1300.0   |
|    1511 |              |        1826 |              |            |      1827 | 5.0        | 15.0     | A           |         2 | 7000.0   |


Table #5
Filename: source_4.csv
Sample Rows in Markdown:
|   WarID | PolityName           |   StartYear | StartMonth   | StartDay   |   EndYear | EndMonth   | EndDay   | Initiator   |   Outcome | Deaths   |
|--------:|:---------------------|------------:|:-------------|:-----------|----------:|:-----------|:---------|:------------|----------:|:---------|
|    1539 | Nian                 |        1855 |              |            |      1858 |            |          | B           |         6 |          |
|    1540 | Costa Rica           |        1856 | 2.0          | 26.0       |      1857 | 5.0        | 1.0      | B           |         2 | 6700.0   |
|    1541 | Yunnan Muslims       |        1856 | 5.0          | 19.0       |      1860 | 10.0       | 24.0     | B           |         4 |          |
|    1542 | Cetshwayo faction    |        1856 | 12.0         | 2.0        |      1856 | 12.0       | 2.0      | A           |         2 |          |
|    1543 | China                |        1857 |              |            |      1857 | 9.0        |          | A           |         2 |          |
|    1544 | Boers                |        1858 |              |            |      1858 |            |          | B           |         6 |          |
|    1545 | Provincial armies    |        1858 |              |            |      1861 | 1.0        |          | B           |         1 |          |
|    1546 | Bambara              |        1860 |              |            |      1862 | 3.0        | 16.0     | A           |         1 |          |
|    1548 | Transvaal government |        1862 | 4.0          |            |      1864 | 1.0        |          | A           |         2 | 3000.0   |
|    1550 | El Salvador          |        1863 | 1.0          | 23.0       |      1863 | 11.0       | 15.0     | A           |         1 |          |


Target Schema:
| PolityName          |   WarID |   StartYear |   StartMonth |   StartDay |   EndYear |   EndMonth |   EndDay |   Initiator |   Outcome |   Deaths |
|:--------------------|--------:|------------:|-------------:|-----------:|----------:|-----------:|---------:|------------:|----------:|---------:|
| El Salvador         |       1 |           1 |            1 |          1 |         1 |          1 |        1 |           1 |         1 |        1 |
| Ngati Ira           |       1 |           1 |            0 |          0 |         1 |          0 |        0 |           1 |         1 |        1 |
| Ngati Maru          |       1 |           1 |            1 |          0 |         1 |          0 |        0 |           1 |         1 |        1 |
| Sikhs               |       1 |           1 |            1 |          1 |         1 |          1 |        1 |           1 |         1 |        0 |
| Te Arawa            |       1 |           1 |            1 |          0 |         1 |          0 |        0 |           1 |         1 |        1 |
| Waikato River Maori |       1 |           1 |            1 |          0 |         1 |          0 |        0 |           1 |         1 |        1 |
| Assam               |       1 |           1 |            0 |          0 |         1 |          0 |        0 |           1 |         1 |        0 |
| Bantu               |       1 |           1 |            0 |          0 |         1 |          1 |        1 |           1 |         1 |        1 |
| Cambodia            |       1 |           1 |            0 |          0 |         1 |          0 |        0 |           1 |         1 |        0 |
| China               |       2 |           2 |            1 |          1 |         2 |          2 |        1 |           2 |         2 |        0 |

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