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:
| state   |   statefp |   countyfp | county_name     |   fips_code | winning_party   | State   | Area_name           |   Civilian_labor_force_2012 |   Employed_2012 |   Unemployed_2012 |   Unemployment_rate_2012 |
|:--------|----------:|-----------:|:----------------|------------:|:----------------|:--------|:--------------------|----------------------------:|----------------:|------------------:|-------------------------:|
| AL      |         1 |          1 | Autauga County  |        1001 | Republican      | AL      | Autauga County, AL  |                       25740 |           23961 |              1779 |                    0.069 |
| AL      |         1 |          3 | Baldwin County  |        1003 | Republican      | AL      | Baldwin County, AL  |                       84414 |           78065 |              6349 |                    0.075 |
| AL      |         1 |          5 | Barbour County  |        1005 | Democrat        | AL      | Barbour County, AL  |                        9362 |            8283 |              1079 |                    0.115 |
| AL      |         1 |          7 | Bibb County     |        1007 | Republican      | AL      | Bibb County, AL     |                        8798 |            8047 |               751 |                    0.085 |
| AL      |         1 |          9 | Blount County   |        1009 | Republican      | AL      | Blount County, AL   |                       24960 |           23244 |              1716 |                    0.069 |
| AL      |         1 |         11 | Bullock County  |        1011 | Democrat        | AL      | Bullock County, AL  |                        4736 |            4245 |               491 |                    0.104 |
| AL      |         1 |         13 | Butler County   |        1013 | Republican      | AL      | Butler County, AL   |                        9088 |            8039 |              1049 |                    0.115 |
| AL      |         1 |         15 | Calhoun County  |        1015 | Republican      | AL      | Calhoun County, AL  |                       49649 |           45252 |              4397 |                    0.089 |
| AL      |         1 |         17 | Chambers County |        1017 | Republican      | AL      | Chambers County, AL |                       15140 |           13646 |              1494 |                    0.099 |
| AL      |         1 |         19 | Cherokee County |        1019 | Republican      | AL      | Cherokee County, AL |                       11268 |           10363 |               905 |                    0.08  |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
| state   |   fips_code | county          |   inactivity_count |   inactivity% |
|:--------|------------:|:----------------|-------------------:|--------------:|
| Alabama |        1001 | Autauga County  |              11310 |          28.7 |
| Alabama |        1003 | Baldwin County  |              36100 |          25.2 |
| Alabama |        1005 | Barbour County  |               6829 |          32.9 |
| Alabama |        1007 | Bibb County     |               5730 |          33.2 |
| Alabama |        1009 | Blount County   |              12130 |          28.5 |
| Alabama |        1011 | Bullock County  |               2719 |          33.1 |
| Alabama |        1013 | Butler County   |               5271 |          34.4 |
| Alabama |        1015 | Calhoun County  |              29470 |          33.6 |
| Alabama |        1017 | Chambers County |               9018 |          34.8 |
| Alabama |        1019 | Cherokee County |               6225 |          31   |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
| state   |   fips_code |   ansi_code | county_name     |   population |   housing_units |   area_land_mt |   area_water_mt |   area_land_mi |   area_water_mi |   latitude |   logitude |
|:--------|------------:|------------:|:----------------|-------------:|----------------:|---------------:|----------------:|---------------:|----------------:|-----------:|-----------:|
| AL      |        1001 |      161526 | Autauga County  |        54571 |           22135 |     1539582278 |        25775735 |        594.436 |           9.952 |    32.5364 |   -86.6445 |
| AL      |        1003 |      161527 | Baldwin County  |       182265 |          104061 |     4117521611 |      1133190229 |       1589.78  |         437.527 |    30.6592 |   -87.7461 |
| AL      |        1005 |      161528 | Barbour County  |        27457 |           11829 |     2291818968 |        50864716 |        884.876 |          19.639 |    31.8707 |   -85.4055 |
| AL      |        1007 |      161529 | Bibb County     |        22915 |            8981 |     1612480789 |         9289057 |        622.582 |           3.587 |    33.0159 |   -87.1271 |
| AL      |        1009 |      161530 | Blount County   |        57322 |           23887 |     1669961855 |        15157440 |        644.776 |           5.852 |    33.9774 |   -86.5672 |
| AL      |        1011 |      161531 | Bullock County  |        10914 |            4493 |     1613056905 |         6056528 |        622.805 |           2.338 |    32.1018 |   -85.7173 |
| AL      |        1013 |      161532 | Butler County   |        20947 |            9964 |     2011976894 |         2726814 |        776.829 |           1.053 |    31.7517 |   -86.682  |
| AL      |        1015 |      161533 | Calhoun County  |       118572 |           53289 |     1569189995 |        16624267 |        605.868 |           6.419 |    33.7717 |   -85.8225 |
| AL      |        1017 |      161534 | Chambers County |        34215 |           17004 |     1545009282 |        17048142 |        596.531 |           6.582 |    32.9179 |   -85.3918 |
| AL      |        1019 |      161535 | Cherokee County |        25989 |           16267 |     1434075952 |       119858898 |        553.7   |          46.278 |    34.0695 |   -85.6542 |


Table #4
Filename: source_3.csv
Sample Rows in Markdown:
| county_name         |   fips_code |   drug_deaths |
|:--------------------|------------:|--------------:|
| Autauga County, AL  |        1001 |            22 |
| Baldwin County, AL  |        1003 |            34 |
| Barbour County, AL  |        1005 |            22 |
| Bibb County, AL     |        1007 |            22 |
| Blount County, AL   |        1009 |            18 |
| Bullock County, AL  |        1011 |            22 |
| Butler County, AL   |        1013 |            22 |
| Calhoun County, AL  |        1015 |            22 |
| Chambers County, AL |        1017 |            22 |
| Cherokee County, AL |        1019 |            22 |


Table #5
Filename: source_4.csv
Sample Rows in Markdown:
|   naics |   fips_code |   unions_count |
|--------:|------------:|---------------:|
|  813930 |        1001 |              5 |
|  813930 |        1003 |              1 |
|  813930 |        1009 |              2 |
|  813930 |        1013 |              1 |
|  813930 |        1015 |              7 |
|  813930 |        1019 |              1 |
|  813930 |        1021 |              1 |
|  813930 |        1023 |              4 |
|  813930 |        1025 |              2 |
|  813930 |        1033 |             14 |


Table #6
Filename: source_5.csv
Sample Rows in Markdown:
| state   |   fips_code | county               |   diabetes_count |   diabetes% |
|:--------|------------:|:---------------------|-----------------:|------------:|
| Montana |       30023 | Deer Lodge County    |              633 |         8.6 |
| Montana |       30025 | Fallon County        |              174 |         7.8 |
| Montana |       30027 | Fergus County        |              782 |         8.7 |
| Montana |       30029 | Flathead County      |             5081 |         7.4 |
| Montana |       30031 | Gallatin County      |             2891 |         4.2 |
| Montana |       30033 | Garfield County      |               72 |         7.6 |
| Montana |       30035 | Glacier County       |             1140 |        12.7 |
| Montana |       30037 | Golden Valley County |               63 |         9.7 |
| Montana |       30039 | Granite County       |              229 |         8.9 |
| Montana |       30041 | Hill County          |             1120 |         9.7 |


Table #7
Filename: source_6.csv
Sample Rows in Markdown:
|   fips_code |   gun_store_counts |
|------------:|-------------------:|
|       10001 |                 18 |
|       10003 |                 51 |
|       10005 |                 72 |
|        1001 |                 21 |
|        1003 |                 69 |
|        1005 |                 10 |
|        1007 |                  3 |
|        1009 |                 19 |
|        1011 |                  1 |
|        1013 |                 10 |


Target Schema:
| state_x   |   statefp |   countyfp | county_name_x   |   fips_code | winning_party   | State   | Area_name           |   Civilian_labor_force_2012 |   Employed_2012 |   Unemployed_2012 |   Unemployment_rate_2012 | state_y   |   ansi_code | county_name_y   |   population |   housing_units |   area_land_mt |   area_water_mt |   area_land_mi |   area_water_mi |   latitude |   logitude |   naics |   unions_count | state_x_25   | county_x        |   diabetes_count |   diabetes% | state_y_29   | county_y        |   inactivity_count |   inactivity% | county_name         |   drug_deaths |   gun_store_counts |
|:----------|----------:|-----------:|:----------------|------------:|:----------------|:--------|:--------------------|----------------------------:|----------------:|------------------:|-------------------------:|:----------|------------:|:----------------|-------------:|----------------:|---------------:|----------------:|---------------:|----------------:|-----------:|-----------:|--------:|---------------:|:-------------|:----------------|-----------------:|------------:|:-------------|:----------------|-------------------:|--------------:|:--------------------|--------------:|-------------------:|
| AL        |         1 |          1 | Autauga County  |        1001 | Republican      | AL      | Autauga County, AL  |                       25740 |           23961 |              1779 |                    0.069 | AL        |      161526 | Autauga County  |        54571 |           22135 |     1539582278 |        25775735 |        594.436 |           9.952 |    32.5364 |   -86.6445 |  813930 |              5 | Alabama      | Autauga County  |             4724 |        12   | Alabama      | Autauga County  |              11310 |          28.7 | Autauga County, AL  |            22 |                 21 |
| AL        |         1 |          3 | Baldwin County  |        1003 | Republican      | AL      | Baldwin County, AL  |                       84414 |           78065 |              6349 |                    0.075 | AL        |      161527 | Baldwin County  |       182265 |          104061 |     4117521611 |      1133190229 |       1589.78  |         437.527 |    30.6592 |   -87.7461 |  813930 |              1 | Alabama      | Baldwin County  |            15437 |        10.8 | Alabama      | Baldwin County  |              36100 |          25.2 | Baldwin County, AL  |            34 |                 69 |
| AL        |         1 |          9 | Blount County   |        1009 | Republican      | AL      | Blount County, AL   |                       24960 |           23244 |              1716 |                    0.069 | AL        |      161530 | Blount County   |        57322 |           23887 |     1669961855 |        15157440 |        644.776 |           5.852 |    33.9774 |   -86.5672 |  813930 |              2 | Alabama      | Blount County   |             5869 |        13.8 | Alabama      | Blount County   |              12130 |          28.5 | Blount County, AL   |            18 |                 19 |
| AL        |         1 |         13 | Butler County   |        1013 | Republican      | AL      | Butler County, AL   |                        9088 |            8039 |              1049 |                    0.115 | AL        |      161532 | Butler County   |        20947 |            9964 |     2011976894 |         2726814 |        776.829 |           1.053 |    31.7517 |   -86.682  |  813930 |              1 | Alabama      | Butler County   |             2507 |        16.4 | Alabama      | Butler County   |               5271 |          34.4 | Butler County, AL   |            22 |                 10 |
| AL        |         1 |         15 | Calhoun County  |        1015 | Republican      | AL      | Calhoun County, AL  |                       49649 |           45252 |              4397 |                    0.089 | AL        |      161533 | Calhoun County  |       118572 |           53289 |     1569189995 |        16624267 |        605.868 |           6.419 |    33.7717 |   -85.8225 |  813930 |              7 | Alabama      | Calhoun County  |            12582 |        14.3 | Alabama      | Calhoun County  |              29470 |          33.6 | Calhoun County, AL  |            22 |                 46 |
| AL        |         1 |         19 | Cherokee County |        1019 | Republican      | AL      | Cherokee County, AL |                       11268 |           10363 |               905 |                    0.08  | AL        |      161535 | Cherokee County |        25989 |           16267 |     1434075952 |       119858898 |        553.7   |          46.278 |    34.0695 |   -85.6542 |  813930 |              1 | Alabama      | Cherokee County |             2993 |        14.9 | Alabama      | Cherokee County |               6225 |          31   | Cherokee County, AL |            22 |                  9 |
| AL        |         1 |         21 | Chilton County  |        1021 | Republican      | AL      | Chilton County, AL  |                       19383 |           17982 |              1401 |                    0.072 | AL        |      161536 | Chilton County  |        43643 |           19278 |     1794483586 |        20586383 |        692.854 |           7.948 |    32.8541 |   -86.7266 |  813930 |              1 | Alabama      | Chilton County  |             4234 |        13.2 | Alabama      | Chilton County  |              10250 |          32   | Chilton County, AL  |            22 |                 15 |
| AL        |         1 |         23 | Choctaw County  |        1023 | Republican      | AL      | Choctaw County, AL  |                        4791 |            4297 |               494 |                    0.103 | AL        |      161537 | Choctaw County  |        13859 |            7269 |     2365954748 |        19059251 |        913.5   |           7.359 |    31.991  |   -88.2489 |  813930 |              4 | Alabama      | Choctaw County  |             1960 |        18.9 | Alabama      | Choctaw County  |               3493 |          33.8 | Choctaw County, AL  |            22 |                  7 |
| AL        |         1 |         25 | Clarke County   |        1025 | Republican      | AL      | Clarke County, AL   |                        8374 |            7116 |              1258 |                    0.15  | AL        |      161538 | Clarke County   |        25833 |           12638 |     3207609488 |        36542656 |       1238.46  |          14.109 |    31.6855 |   -87.8186 |  813930 |              2 | Alabama      | Clarke County   |             2948 |        15.8 | Alabama      | Clarke County   |               5630 |          30.2 | Clarke County, AL   |            22 |                 16 |
| AL        |         1 |         33 | Colbert County  |        1033 | Republican      | AL      | Colbert County, AL  |                       24026 |           21922 |              2104 |                    0.088 | AL        |      161542 | Colbert County  |        54428 |           25758 |     1534877333 |        76430813 |        592.619 |          29.51  |    34.7031 |   -87.8015 |  813930 |             14 | Alabama      | Colbert County  |             6928 |        16.8 | Alabama      | Colbert County  |              12260 |          29.7 | Colbert County, AL  |            22 |                 19 |

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
source_6.csv
test: test_0.csv
test_1.csv
test_2.csv
test_3.csv
test_4.csv
test_5.csv
test_6.csv