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:
|   School ID | name                  | type     |   size |   budget |
|------------:|:----------------------|:---------|-------:|---------:|
|           0 | Huang High School     | District |   2917 |  1910635 |
|           1 | Figueroa High School  | District |   2949 |  1884411 |
|           2 | Shelton High School   | Charter  |   1761 |  1056600 |
|           3 | Hernandez High School | District |   4635 |  3022020 |
|           4 | Griffin High School   | Charter  |   1468 |   917500 |
|           5 | Wilson High School    | Charter  |   2283 |  1319574 |
|           6 | Cabrera High School   | Charter  |   1858 |  1081356 |
|           7 | Bailey High School    | District |   4976 |  3124928 |
|           8 | Holden High School    | Charter  |    427 |   248087 |
|           9 | Pena High School      | Charter  |    962 |   585858 |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|   Student ID | name                | gender   | grade   | school             |   reading_score |   math_score |
|-------------:|:--------------------|:---------|:--------|:-------------------|----------------:|-------------:|
|        19585 | Alicia Butler       | F        | 9th     | Bailey High School |              69 |           71 |
|        19586 | Amanda Adams        | F        | 11th    | Bailey High School |              91 |           83 |
|        19587 | James Brown         | M        | 9th     | Bailey High School |              76 |           92 |
|        19588 | Anthony Holmes      | M        | 11th    | Bailey High School |              86 |           76 |
|        19589 | Jacqueline Williams | F        | 10th    | Bailey High School |              79 |           75 |
|        19590 | Julie Brown         | F        | 11th    | Bailey High School |              94 |           99 |
|        19591 | Scott Gibson        | M        | 11th    | Bailey High School |              91 |           71 |
|        19592 | Anthony Reeves      | M        | 12th    | Bailey High School |              99 |           60 |
|        19593 | Diane Vargas        | F        | 9th     | Bailey High School |              99 |           80 |
|        19594 | Kathryn Jones       | F        | 10th    | Bailey High School |              73 |           97 |


Target Schema:
| School Name          | Student Grade   |   School ID |   School Size |   School Budget |   Student ID |   Student Reading Score |   Average Student Math Score |
|:---------------------|:----------------|------------:|--------------:|----------------:|-------------:|------------------------:|-----------------------------:|
| Bailey High School   | 10th            |           7 |          4976 |         3124928 |     18708.3  |                 80.8629 |                      76.4563 |
| Bailey High School   | 11th            |           7 |          4976 |         3124928 |     18729.7  |                 80.8585 |                      78.3063 |
| Bailey High School   | 12th            |           7 |          4976 |         3124928 |     18688.1  |                 81.1541 |                      76.6773 |
| Bailey High School   | 9th             |           7 |          4976 |         3124928 |     18767.7  |                 80.657  |                      76.907  |
| Cabrera High School  | 10th            |           6 |          1858 |         1081356 |     16909.5  |                 84.2532 |                      83.1545 |
| Cabrera High School  | 11th            |           6 |          1858 |         1081356 |     16955    |                 83.7884 |                      82.7656 |
| Cabrera High School  | 12th            |           6 |          1858 |         1081356 |     16924.6  |                 84.288  |                      83.2775 |
| Cabrera High School  | 9th             |           6 |          1858 |         1081356 |     16969.6  |                 83.6761 |                      83.0947 |
| Figueroa High School | 10th            |           1 |          2949 |         1884411 |      4332.7  |                 81.4089 |                      76.54   |
| Figueroa High School | 11th            |           1 |          2949 |         1884411 |      4424.48 |                 80.6403 |                      76.8843 |

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
test: test_0.csv
test_1.csv