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:
| Age Group    | Sex    |   Don't know/Refused/Missing |   Normal Weight |   Obese |   Overweight |   Underweight |
|:-------------|:-------|-----------------------------:|----------------:|--------:|-------------:|--------------:|
| Age 18 to 24 | Female |                          569 |            2801 |     881 |         1117 |           265 |
| Age 18 to 24 | Male   |                          255 |            3001 |     870 |         1689 |           201 |
| Age 25 to 34 | Female |                         1497 |            4172 |    2754 |         2558 |           209 |
| Age 25 to 34 | Male   |                          392 |            2955 |    2291 |         3593 |           104 |
| Age 35 to 44 | Female |                         1471 |            5290 |    4251 |         3841 |           226 |
| Age 35 to 44 | Male   |                          416 |            2497 |    3380 |         4523 |            63 |
| Age 45 to 54 | Female |                         1991 |            7285 |    6472 |         5997 |           370 |
| Age 45 to 54 | Male   |                          584 |            3339 |    5484 |         6918 |           103 |
| Age 55 to 64 | Female |                         3147 |            9451 |    9153 |         8723 |           464 |
| Age 55 to 64 | Male   |                          686 |            4718 |    7095 |         9305 |           163 |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
| Age Group       | Sex     | Don't know/Refused/Missing   | Normal Weight   | Obese   | Overweight   | Underweight   |
|:----------------|:--------|:-----------------------------|:----------------|:--------|:-------------|:--------------|
| Age 45 to 54    | Female  | 2644.0                       | 6470.0          | 6236.0  | 5582.0       | 298.0         |
| Age 45 to 54    | Male    | 904.0                        | 3217.0          | 5837.0  | 6903.0       | 111.0         |
| Age 45 to 54    | Refused | 1.0                          | 1.0             |         |              |               |
| Age 55 to 64    | Female  | 3739.0                       | 9032.0          | 8744.0  | 8220.0       | 511.0         |
| Age 55 to 64    | Male    | 946.0                        | 4708.0          | 7455.0  | 9533.0       | 159.0         |
| Age 55 to 64    | Refused | 1.0                          |                 |         |              |               |
| Age 65 or older | Female  | 4989.0                       | 17735.0         | 12840.0 | 16050.0      | 1216.0        |
| Age 65 or older | Male    | 1094.0                       | 8677.0          | 9147.0  | 15051.0      | 277.0         |
| Age 65 or older | Refused |                              | 2.0             |         |              |               |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
| Age Group    | Sex    |   Don't know/Refused/Missing |   Normal Weight |   Obese |   Overweight |   Underweight |
|:-------------|:-------|-----------------------------:|----------------:|--------:|-------------:|--------------:|
| Age 18 to 24 | Female |                          688 |            2911 |     888 |         1154 |           276 |
| Age 18 to 24 | Male   |                          365 |            2957 |    1065 |         1750 |           207 |
| Age 25 to 34 | Female |                         1680 |            4023 |    2761 |         2501 |           247 |
| Age 25 to 34 | Male   |                          568 |            3111 |    2421 |         3686 |           113 |
| Age 35 to 44 | Female |                         1630 |            4660 |    3966 |         3479 |           224 |
| Age 35 to 44 | Male   |                          573 |            2450 |    3487 |         4404 |            73 |
| Age 45 to 54 | Female |                         2401 |            6284 |    5765 |         5279 |           325 |
| Age 45 to 54 | Male   |                          808 |            3128 |    5194 |         6520 |            75 |
| Age 55 to 64 | Female |                         3398 |            8276 |    8104 |         7792 |           425 |
| Age 55 to 64 | Male   |                          897 |            4287 |    6770 |         8709 |           130 |


Table #4
Filename: source_3.csv
Sample Rows in Markdown:
| Age Group    | Sex    |   Don't know/Refused/Missing |   Normal Weight |   Obese |   Overweight |   Underweight |
|:-------------|:-------|-----------------------------:|----------------:|--------:|-------------:|--------------:|
| Age 18 to 24 | Female |                          626 |            3290 |     997 |         1336 |           321 |
| Age 18 to 24 | Male   |                          187 |            3304 |     970 |         1859 |           218 |
| Age 25 to 34 | Female |                         1600 |            5057 |    3073 |         3026 |           306 |
| Age 25 to 34 | Male   |                          307 |            3476 |    2519 |         4081 |           110 |
| Age 35 to 44 | Female |                         1513 |            6103 |    4700 |         4263 |           268 |
| Age 35 to 44 | Male   |                          341 |            2872 |    3862 |         5221 |            73 |
| Age 45 to 54 | Female |                         1771 |            8141 |    7234 |         6696 |           411 |
| Age 45 to 54 | Male   |                          363 |            3682 |    5811 |         7330 |           109 |
| Age 55 to 64 | Female |                         2785 |           10237 |    9754 |         9254 |           536 |
| Age 55 to 64 | Male   |                          423 |            4901 |    7192 |         9444 |           139 |


Table #5
Filename: source_4.csv
Sample Rows in Markdown:
| Age Group    | Sex    |   Don't know/Refused/Missing |   Normal Weight |   Obese |   Overweight |   Underweight |
|:-------------|:-------|-----------------------------:|----------------:|--------:|-------------:|--------------:|
| Age 18 to 24 | Female |                          569 |            3113 |     937 |         1177 |           313 |
| Age 18 to 24 | Male   |                          143 |            3003 |     857 |         1642 |           191 |
| Age 25 to 34 | Female |                         1449 |            5099 |    3116 |         3053 |           296 |
| Age 25 to 34 | Male   |                          243 |            3159 |    2414 |         3933 |           109 |
| Age 35 to 44 | Female |                         1364 |            6409 |    4548 |         4558 |           265 |
| Age 35 to 44 | Male   |                          276 |            2684 |    3882 |         5395 |            78 |
| Age 45 to 54 | Female |                         1803 |            8617 |    7250 |         6649 |           388 |
| Age 45 to 54 | Male   |                          332 |            3696 |    5618 |         7609 |            90 |
| Age 55 to 64 | Female |                         2774 |           10072 |    9414 |         9155 |           515 |
| Age 55 to 64 | Male   |                          392 |            4551 |    6839 |         9220 |           138 |


Target Schema:
| Sex     |   Age Group |   Don't know/Refused/Missing |   Normal Weight |   Obese |   Overweight |   Underweight |
|:--------|------------:|-----------------------------:|----------------:|--------:|-------------:|--------------:|
| Female  |          27 |                           27 |              27 |      27 |           27 |            27 |
| Male    |          27 |                           27 |              27 |      27 |           27 |            27 |
| Refused |           3 |                            1 |               3 |       1 |            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