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:
|   ULCS_NO | SCHOOL_YEAR   | INCIDENT_TYPE                |   INCIDENT_COUNT |   SCHOOL_ID |
|----------:|:--------------|:-----------------------------|-----------------:|------------:|
|      5440 | 2015-2016     | GRAFFITI                     |                0 |         544 |
|      5440 | 2015-2016     | ASSAULTS                     |                4 |         544 |
|      5440 | 2015-2016     | SUICIDE - ATTEMPTS & THREATS |                0 |         544 |
|      5440 | 2015-2016     | DRUG & ALCOHOL OFFENSES      |                0 |         544 |
|      5440 | 2015-2016     | HARASSMENT                   |                0 |         544 |
|      5440 | 2015-2016     | VANDALISM                    |                5 |         544 |
|      5440 | 2015-2016     | THREATS                      |                2 |         544 |
|      5440 | 2015-2016     | ROBBERY                      |                0 |         544 |
|      5440 | 2015-2016     | WEAPONS                      |                0 |         544 |
|      5440 | 2015-2016     | BULLYING                     |                0 |         544 |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|   ULCS_NO | SCHOOL_YEAR   | INCIDENT_TYPE           |   INCIDENT_COUNT |   SCHOOL_ID |
|----------:|:--------------|:------------------------|-----------------:|------------:|
|      4020 | 2014-2015     | BULLYING                |                0 |         402 |
|      4020 | 2014-2015     | DRUGS & ALCOHOL OFFENSE |               20 |         402 |
|      4030 | 2014-2015     | FIRE - INCENDIARY       |                0 |         403 |
|      4030 | 2014-2015     | THEFT                   |                1 |         403 |
|      4100 | 2014-2015     | BULLYING                |                1 |         410 |
|      4100 | 2014-2015     | DISORDERLY CONDUCT      |               14 |         410 |
|      4100 | 2014-2015     | FIRE - INCENDIARY       |                1 |         410 |
|      4100 | 2014-2015     | HARASSMENT              |                2 |         410 |
|      4100 | 2014-2015     | TAKE OFF                |                0 |         410 |
|      4100 | 2014-2015     | WEAPONS                 |                5 |         410 |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
|   ULCS_NO | SCHOOL_YEAR   | INCIDENT_TYPE           |   INCIDENT_COUNT |   SCHOOL_ID |
|----------:|:--------------|:------------------------|-----------------:|------------:|
|      5260 | 2013-2014     | HARASSMENT              |                1 |         526 |
|      5340 | 2013-2014     | ASSAULTS                |                5 |         534 |
|      5350 | 2013-2014     | THREATS                 |                8 |         535 |
|      5370 | 2013-2014     | TAKE OFF                |                0 |         537 |
|      5450 | 2013-2014     | DRUGS & ALCOHOL OFFENSE |                0 |         545 |
|      5480 | 2013-2014     | BURGLARY                |                0 |         548 |
|      5510 | 2013-2014     | TRESPASSING             |                1 |         551 |
|      5520 | 2013-2014     | BULLYING                |                0 |         552 |
|      5530 | 2013-2014     | WEAPONS                 |                0 |         553 |
|      6010 | 2013-2014     | ASSAULTS                |                1 |         601 |


Table #4
Filename: source_3.csv
Sample Rows in Markdown:
|   ULCS_NO |   SCHOOL_ID | SCHOOL_YEAR   | INCIDENT_TYPE                |   INCIDENT_COUNT |
|----------:|------------:|:--------------|:-----------------------------|-----------------:|
|      1010 |         101 | 2016-2017     | Assaults                     |               18 |
|      1010 |         101 | 2016-2017     | Disorderly Conduct           |               21 |
|      1010 |         101 | 2016-2017     | Drug and Alcohol Offenses    |                2 |
|      1010 |         101 | 2016-2017     | Harassment                   |                1 |
|      1010 |         101 | 2016-2017     | Morals Offenses              |                2 |
|      1010 |         101 | 2016-2017     | Threats - Verbal and Written |                2 |
|      1010 |         101 | 2016-2017     | Trespassing                  |                1 |
|      1010 |         101 | 2016-2017     | Vandalism                    |                2 |
|      1010 |         101 | 2016-2017     | Weapons Offenses             |                6 |
|      1020 |         102 | 2016-2017     | Assaults                     |                9 |


Target Schema:
| SCHOOL_YEAR   |   ULCS_NO |   INCIDENT_TYPE |   INCIDENT_COUNT |   SCHOOL_ID |
|:--------------|----------:|----------------:|-----------------:|------------:|
| 2013-2014     |      3723 |            3723 |             3723 |        3723 |
| 2014-2015     |      3672 |            3672 |             3672 |        3672 |
| 2015-2016     |      2057 |            2057 |             2057 |        2057 |
| 2016-2017     |      1409 |            1409 |             1409 |        1409 |

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