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               |   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 #2
Filename: source_1.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 #3
Filename: source_2.csv
Sample Rows in Markdown:
|   CountyID | CountyName                     |   aian_population |   Year |       ID |
|-----------:|:-------------------------------|------------------:|-------:|---------:|
|       2020 | Anchorage Municipality, Alaska |              8091 |   2000 | 20202000 |
|       4001 | Apache County, Arizona         |             12081 |   2000 | 40012000 |
|       4005 | Coconino County, Arizona       |              8367 |   2000 | 40052000 |
|       4013 | Maricopa County, Arizona       |             20744 |   2000 | 40132000 |
|       4017 | Navajo County, Arizona         |             13271 |   2000 | 40172000 |
|       4019 | Pima County, Arizona           |             10882 |   2000 | 40192000 |
|       6037 | Los Angeles County, California |             14517 |   2000 | 60372000 |
|       6059 | Orange County, California      |              3981 |   2000 | 60592000 |
|       6065 | Riverside County, California   |              6481 |   2000 | 60652000 |
|       6067 | Sacramento County, California  |              5239 |   2000 | 60672000 |


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 |


Table #5
Filename: source_4.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 #6
Filename: source_5.csv
Sample Rows in Markdown:
|   CountyID | CountyName               |   hispanic_population |   Year |       ID |
|-----------:|:-------------------------|----------------------:|-------:|---------:|
|       1001 | Autauga County, Alabama  |                   107 |   2000 | 10012000 |
|       1003 | Baldwin County, Alabama  |                   605 |   2000 | 10032000 |
|       1005 | Barbour County, Alabama  |                   103 |   2000 | 10052000 |
|       1007 | Bibb County, Alabama     |                    43 |   2000 | 10072000 |
|       1009 | Blount County, Alabama   |                   606 |   2000 | 10092000 |
|       1011 | Bullock County, Alabama  |                    78 |   2000 | 10112000 |
|       1013 | Butler County, Alabama   |                    73 |   2000 | 10132000 |
|       1015 | Calhoun County, Alabama  |                   597 |   2000 | 10152000 |
|       1017 | Chambers County, Alabama |                   108 |   2000 | 10172000 |
|       1019 | Cherokee County, Alabama |                    49 |   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                |   hispanic_population |   Year_y_16 |   CountyID_x_17 | CountyName_x_18                |   black_population |   Year_x_20 |   CountyID_y_21 | CountyName_y_22                |   aian_population |   Year_y_24 |
|-------------:|:-------------------------------|--------------------:|---------:|---------:|-------------:|:-------------------------------|-------------------:|---------:|---------------:|:-------------------------------|-------------------:|------------:|----------------:|:-------------------------------|----------------------:|------------:|----------------:|:-------------------------------|-------------------:|------------:|----------------:|:-------------------------------|------------------:|------------:|
|         2020 | Anchorage Municipality, Alaska |               74229 |     2000 | 20202000 |         2020 | Anchorage Municipality, Alaska |               1618 |     2000 |           2020 | Anchorage Municipality, Alaska |               3596 |        2000 |            2020 | Anchorage Municipality, Alaska |                  3889 |        2000 |            2020 | Anchorage Municipality, Alaska |               5388 |        2000 |            2020 | Anchorage Municipality, Alaska |              8091 |        2000 |
|         2020 | Anchorage Municipality, Alaska |               74229 |     2000 | 20202000 |         2020 | Anchorage Municipality, Alaska |               1618 |     2000 |           2020 | Anchorage Municipality, Alaska |               3596 |        2000 |            2020 | Anchorage Municipality, Alaska |                  3889 |        2000 |            2020 | Anchorage Municipality, Alaska |               5388 |        2000 |            2020 | Anchorage Municipality, Alaska |              8091 |        2000 |
|         4001 | Apache County, Arizona         |                5143 |     2000 | 40012000 |         4001 | Apache County, Arizona         |                329 |     2000 |           4001 | Apache County, Arizona         |                201 |        2000 |            4001 | Apache County, Arizona         |                   816 |        2000 |            4001 | Apache County, Arizona         |                 29 |        2000 |            4001 | Apache County, Arizona         |             12081 |        2000 |
|         4001 | Apache County, Arizona         |                5143 |     2000 | 40012000 |         4001 | Apache County, Arizona         |                329 |     2000 |           4001 | Apache County, Arizona         |                201 |        2000 |            4001 | Apache County, Arizona         |                   816 |        2000 |            4001 | Apache County, Arizona         |                 29 |        2000 |            4001 | Apache County, Arizona         |             12081 |        2000 |
|         4005 | Coconino County, Arizona       |               29387 |     2000 | 40052000 |         4005 | Coconino County, Arizona       |               1311 |     2000 |           4005 | Coconino County, Arizona       |                585 |        2000 |            4005 | Coconino County, Arizona       |                  3617 |        2000 |            4005 | Coconino County, Arizona       |                501 |        2000 |            4005 | Coconino County, Arizona       |              8367 |        2000 |
|         4005 | Coconino County, Arizona       |               29387 |     2000 | 40052000 |         4005 | Coconino County, Arizona       |               1311 |     2000 |           4005 | Coconino County, Arizona       |                585 |        2000 |            4005 | Coconino County, Arizona       |                  3617 |        2000 |            4005 | Coconino County, Arizona       |                501 |        2000 |            4005 | Coconino County, Arizona       |              8367 |        2000 |
|         4013 | Maricopa County, Arizona       |              942545 |     2000 | 40132000 |         4013 | Maricopa County, Arizona       |              87938 |     2000 |           4013 | Maricopa County, Arizona       |              23455 |        2000 |            4013 | Maricopa County, Arizona       |                186066 |        2000 |            4013 | Maricopa County, Arizona       |              40573 |        2000 |            4013 | Maricopa County, Arizona       |             20744 |        2000 |
|         4013 | Maricopa County, Arizona       |              942545 |     2000 | 40132000 |         4013 | Maricopa County, Arizona       |              87938 |     2000 |           4013 | Maricopa County, Arizona       |              23455 |        2000 |            4013 | Maricopa County, Arizona       |                186066 |        2000 |            4013 | Maricopa County, Arizona       |              40573 |        2000 |            4013 | Maricopa County, Arizona       |             20744 |        2000 |
|         4017 | Navajo County, Arizona         |               16674 |     2000 | 40172000 |         4017 | Navajo County, Arizona         |                943 |     2000 |           4017 | Navajo County, Arizona         |                487 |        2000 |            4017 | Navajo County, Arizona         |                  2056 |        2000 |            4017 | Navajo County, Arizona         |                246 |        2000 |            4017 | Navajo County, Arizona         |             13271 |        2000 |
|         4017 | Navajo County, Arizona         |               16674 |     2000 | 40172000 |         4017 | Navajo County, Arizona         |                943 |     2000 |           4017 | Navajo County, Arizona         |                487 |        2000 |            4017 | Navajo County, Arizona         |                  2056 |        2000 |            4017 | Navajo County, Arizona         |                246 |        2000 |            4017 | Navajo County, Arizona         |             13271 |        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
source_4.csv
source_5.csv
test: test_0.csv
test_1.csv
test_2.csv
test_3.csv
test_4.csv
test_5.csv