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:
|   CountyID | CountyName               |   mixed_population |   Year |       ID |
|-----------:|:-------------------------|-------------------:|-------:|---------:|
|       1001 | Autauga County, Alabama  |                171 |   2000 | 10012000 |
|       1003 | Baldwin County, Alabama  |                566 |   2000 | 10032000 |
|       1005 | Barbour County, Alabama  |                 75 |   2000 | 10052000 |
|       1007 | Bibb County, Alabama     |                 61 |   2000 | 10072000 |
|       1009 | Blount County, Alabama   |                183 |   2000 | 10092000 |
|       1011 | Bullock County, Alabama  |                 37 |   2000 | 10112000 |
|       1013 | Butler County, Alabama   |                 21 |   2000 | 10132000 |
|       1015 | Calhoun County, Alabama  |                420 |   2000 | 10152000 |
|       1017 | Chambers County, Alabama |                 48 |   2000 | 10172000 |
|       1019 | Cherokee County, Alabama |                 18 |   2000 | 10192000 |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|   CountyID | CountyName               |   whites_population |   Year |       ID |
|-----------:|:-------------------------|--------------------:|-------:|---------:|
|       1001 | Autauga County, Alabama  |               13103 |   2000 | 10012000 |
|       1003 | Baldwin County, Alabama  |               49458 |   2000 | 10032000 |
|       1005 | Barbour County, Alabama  |                5815 |   2000 | 10052000 |
|       1007 | Bibb County, Alabama     |                5978 |   2000 | 10072000 |
|       1009 | Blount County, Alabama   |               18397 |   2000 | 10092000 |
|       1011 | Bullock County, Alabama  |                1014 |   2000 | 10112000 |
|       1013 | Butler County, Alabama   |                5231 |   2000 | 10132000 |
|       1015 | Calhoun County, Alabama  |               36645 |   2000 | 10152000 |
|       1017 | Chambers County, Alabama |                9438 |   2000 | 10172000 |
|       1019 | Cherokee County, Alabama |                9153 |   2000 | 10192000 |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
|   CountyID | CountyName                  |   other_population |   Year |        ID |
|-----------:|:----------------------------|-------------------:|-------:|----------:|
|      17079 | Jasper County, Illinois     |                  7 |   2000 | 170792000 |
|      17081 | Jefferson County, Illinois  |                 29 |   2000 | 170812000 |
|      17083 | Jersey County, Illinois     |                  0 |   2000 | 170832000 |
|      17085 | Jo Daviess County, Illinois |                 25 |   2000 | 170852000 |
|      17087 | Johnson County, Illinois    |                  0 |   2000 | 170872000 |
|      17089 | Kane County, Illinois       |               9098 |   2000 | 170892000 |
|      17091 | Kankakee County, Illinois   |                625 |   2000 | 170912000 |
|      17093 | Kendall County, Illinois    |                517 |   2000 | 170932000 |
|      17095 | Knox County, Illinois       |                199 |   2000 | 170952000 |
|      17097 | Lake County, Illinois       |               9573 |   2000 | 170972000 |


Table #4
Filename: source_3.csv
Sample Rows in Markdown:
|   CountyID | CountyName               |   black_population |   Year |       ID |
|-----------:|:-------------------------|-------------------:|-------:|---------:|
|       1001 | Autauga County, Alabama  |               2566 |   2000 | 10012000 |
|       1003 | Baldwin County, Alabama  |               4650 |   2000 | 10032000 |
|       1005 | Barbour County, Alabama  |               4446 |   2000 | 10052000 |
|       1007 | Bibb County, Alabama     |               1306 |   2000 | 10072000 |
|       1009 | Blount County, Alabama   |                146 |   2000 | 10092000 |
|       1011 | Bullock County, Alabama  |               2921 |   2000 | 10112000 |
|       1013 | Butler County, Alabama   |               3117 |   2000 | 10132000 |
|       1015 | Calhoun County, Alabama  |               7731 |   2000 | 10152000 |
|       1017 | Chambers County, Alabama |               5002 |   2000 | 10172000 |
|       1019 | Cherokee County, Alabama |                461 |   2000 | 10192000 |


Target Schema:
|   CountyID_x | CountyName_x            |   whites_population |   Year_x |       ID |   CountyID_y | CountyName_y            |   other_population |   Year_y |   CountyID_x_9 | CountyName_x_10         |   mixed_population |   Year_x_12 |   CountyID_y_13 | CountyName_y_14         |   black_population |   Year_y_16 |
|-------------:|:------------------------|--------------------:|---------:|---------:|-------------:|:------------------------|-------------------:|---------:|---------------:|:------------------------|-------------------:|------------:|----------------:|:------------------------|-------------------:|------------:|
|         1001 | Autauga County, Alabama |               13103 |     2000 | 10012000 |         1001 | Autauga County, Alabama |                 31 |     2000 |           1001 | Autauga County, Alabama |                171 |        2000 |            1001 | Autauga County, Alabama |               2566 |        2000 |
|         1001 | Autauga County, Alabama |               13103 |     2000 | 10012000 |         1001 | Autauga County, Alabama |                 31 |     2000 |           1001 | Autauga County, Alabama |                171 |        2000 |            1001 | Autauga County, Alabama |               2566 |        2000 |
|         1003 | Baldwin County, Alabama |               49458 |     2000 | 10032000 |         1003 | Baldwin County, Alabama |                212 |     2000 |           1003 | Baldwin County, Alabama |                566 |        2000 |            1003 | Baldwin County, Alabama |               4650 |        2000 |
|         1003 | Baldwin County, Alabama |               49458 |     2000 | 10032000 |         1003 | Baldwin County, Alabama |                212 |     2000 |           1003 | Baldwin County, Alabama |                566 |        2000 |            1003 | Baldwin County, Alabama |               4650 |        2000 |
|         1005 | Barbour County, Alabama |                5815 |     2000 | 10052000 |         1005 | Barbour County, Alabama |                 57 |     2000 |           1005 | Barbour County, Alabama |                 75 |        2000 |            1005 | Barbour County, Alabama |               4446 |        2000 |
|         1005 | Barbour County, Alabama |                5815 |     2000 | 10052000 |         1005 | Barbour County, Alabama |                 57 |     2000 |           1005 | Barbour County, Alabama |                 75 |        2000 |            1005 | Barbour County, Alabama |               4446 |        2000 |
|         1007 | Bibb County, Alabama    |                5978 |     2000 | 10072000 |         1007 | Bibb County, Alabama    |                 15 |     2000 |           1007 | Bibb County, Alabama    |                 61 |        2000 |            1007 | Bibb County, Alabama    |               1306 |        2000 |
|         1007 | Bibb County, Alabama    |                5978 |     2000 | 10072000 |         1007 | Bibb County, Alabama    |                 15 |     2000 |           1007 | Bibb County, Alabama    |                 61 |        2000 |            1007 | Bibb County, Alabama    |               1306 |        2000 |
|         1009 | Blount County, Alabama  |               18397 |     2000 | 10092000 |         1009 | Blount County, Alabama  |                307 |     2000 |           1009 | Blount County, Alabama  |                183 |        2000 |            1009 | Blount County, Alabama  |                146 |        2000 |
|         1009 | Blount County, Alabama  |               18397 |     2000 | 10092000 |         1009 | Blount County, Alabama  |                307 |     2000 |           1009 | Blount County, Alabama  |                183 |        2000 |            1009 | Blount County, Alabama  |                146 |        2000 |

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