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:
|   zipcode |   counts |
|----------:|---------:|
|     10001 |      178 |
|     10002 |      231 |
|     10003 |      285 |
|     10004 |        7 |
|     10005 |        2 |
|     10006 |        2 |
|     10007 |       26 |
|     10009 |      305 |
|     10010 |       82 |
|     10011 |      296 |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|   zipcode |   counts |
|----------:|---------:|
|     10001 |      473 |
|     10002 |     2904 |
|     10003 |     1741 |
|     10004 |       65 |
|     10005 |       25 |
|     10006 |       86 |
|     10007 |      233 |
|     10009 |     2820 |
|     10010 |      286 |
|     10011 |     1027 |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
| boro   |   zipcode |
|:-------|----------:|
| Bronx  |     10453 |
| Bronx  |     10457 |
| Bronx  |     10460 |
| Bronx  |     10458 |
| Bronx  |     10467 |
| Bronx  |     10468 |
| Bronx  |     10451 |
| Bronx  |     10452 |
| Bronx  |     10456 |
| Bronx  |     10454 |


Table #4
Filename: source_3.csv
Sample Rows in Markdown:
|   zipcode |   total_crime |   violation |   misdemeanor |   felony |
|----------:|--------------:|------------:|--------------:|---------:|
|     10001 |         54025 |        4111 |         29699 |    20215 |
|     10002 |         52124 |        5738 |         31193 |    15193 |
|     10003 |         55283 |        4390 |         32604 |    18289 |
|     10004 |          5816 |         681 |          3302 |     1833 |
|     10007 |          6702 |         668 |          3885 |     2149 |
|     10008 |          7426 |         199 |          5996 |     1231 |
|     10009 |         28144 |        3827 |         16146 |     8171 |
|     10010 |         19199 |        1978 |          9996 |     7225 |
|     10011 |         33067 |        3136 |         18026 |    11905 |
|     10012 |         32189 |        1764 |         19832 |    10593 |


Table #5
Filename: source_4.csv
Sample Rows in Markdown:
|   zipcode | businesses   |   counts |
|----------:|:-------------|---------:|
|     10001 | Pawnbroker   |        1 |
|     10002 | Pawnbroker   |        5 |
|     10005 | Pawnbroker   |        1 |
|     10009 | Pawnbroker   |        1 |
|     10010 | Pawnbroker   |        2 |
|     10011 | Pawnbroker   |        1 |
|     10017 | Pawnbroker   |        5 |
|     10018 | Pawnbroker   |        2 |
|     10019 | Pawnbroker   |        1 |
|     10020 | Pawnbroker   |        2 |


Table #6
Filename: source_5.csv
Sample Rows in Markdown:
|   zipcode | indicator         |   counts |
|----------:|:------------------|---------:|
|     10001 | Passed Inspection |     4371 |
|     10002 | Passed Inspection |    13666 |
|     10003 | Passed Inspection |    12229 |
|     10004 | Passed Inspection |      615 |
|     10005 | Passed Inspection |      390 |
|     10006 | Passed Inspection |      356 |
|     10007 | Passed Inspection |     1461 |
|     10009 | Passed Inspection |    11014 |
|     10010 | Passed Inspection |     2939 |
|     10011 | Passed Inspection |     9580 |


Table #7
Filename: source_6.csv
Sample Rows in Markdown:
|   zipcode | businesses    |   counts |
|----------:|:--------------|---------:|
|     10001 | Sidewalk Cafe |       10 |
|     10002 | Sidewalk Cafe |       14 |
|     10003 | Sidewalk Cafe |       85 |
|     10004 | Sidewalk Cafe |        1 |
|     10006 | Sidewalk Cafe |        1 |
|     10007 | Sidewalk Cafe |        4 |
|     10009 | Sidewalk Cafe |       28 |
|     10010 | Sidewalk Cafe |       21 |
|     10011 | Sidewalk Cafe |       44 |
|     10012 | Sidewalk Cafe |       60 |


Table #8
Filename: source_7.csv
Sample Rows in Markdown:
|   zipcode | businesses             |   counts |
|----------:|:-----------------------|---------:|
|     10001 | Debt Collection Agency |        5 |
|     10003 | Debt Collection Agency |        2 |
|     10004 | Debt Collection Agency |        3 |
|     10005 | Debt Collection Agency |        1 |
|     10006 | Debt Collection Agency |        4 |
|     10007 | Debt Collection Agency |        1 |
|     10010 | Debt Collection Agency |        1 |
|     10011 | Debt Collection Agency |        1 |
|     10013 | Debt Collection Agency |        1 |
|     10016 | Debt Collection Agency |        5 |


Table #9
Filename: source_8.csv
Sample Rows in Markdown:
|   zipcode | businesses              |   counts |
|----------:|:------------------------|---------:|
|     10474 | Cigarette Retail Dealer |       21 |
|     10475 | Cigarette Retail Dealer |       17 |
|     11001 | Cigarette Retail Dealer |        1 |
|     11004 | Cigarette Retail Dealer |        8 |
|     11005 | Cigarette Retail Dealer |        2 |
|     11040 | Cigarette Retail Dealer |        1 |
|     11101 | Cigarette Retail Dealer |       64 |
|     11102 | Cigarette Retail Dealer |       38 |
|     11103 | Cigarette Retail Dealer |       56 |
|     11104 | Cigarette Retail Dealer |       36 |


Target Schema:
|   zipcode | businesses_x   |   counts_x | businesses_y   |   counts_y | businesses_x_5         |   counts_x_6 | businesses_y_7          |   counts_y_8 | boro      |   counts_x_10 |   counts_y_11 | indicator         |   counts |   total_crime |   violation |   misdemeanor |   felony |
|----------:|:---------------|-----------:|:---------------|-----------:|:-----------------------|-------------:|:------------------------|-------------:|:----------|--------------:|--------------:|:------------------|---------:|--------------:|------------:|--------------:|---------:|
|     10001 | Sidewalk Cafe  |         10 | Pawnbroker     |          1 | Debt Collection Agency |            5 | Cigarette Retail Dealer |           98 | Manhattan |           178 |           473 | Passed Inspection |     4371 |         54025 |        4111 |         29699 |    20215 |
|     10010 | Sidewalk Cafe  |         21 | Pawnbroker     |          2 | Debt Collection Agency |            1 | Cigarette Retail Dealer |           45 | Manhattan |            82 |           286 | Passed Inspection |     2939 |         19199 |        1978 |          9996 |     7225 |
|     10011 | Sidewalk Cafe  |         44 | Pawnbroker     |          1 | Debt Collection Agency |            1 | Cigarette Retail Dealer |           69 | Manhattan |           296 |          1027 | Passed Inspection |     9580 |         33067 |        3136 |         18026 |    11905 |
|     10017 | Sidewalk Cafe  |          7 | Pawnbroker     |          5 | Debt Collection Agency |            4 | Cigarette Retail Dealer |           57 | Manhattan |            41 |           112 | Passed Inspection |     2249 |          8258 |         753 |          4132 |     3373 |
|     10018 | Sidewalk Cafe  |          1 | Pawnbroker     |          2 | Debt Collection Agency |            2 | Cigarette Retail Dealer |           74 | Manhattan |            52 |           184 | Passed Inspection |     2323 |         20819 |        1280 |         11166 |     8373 |
|     10019 | Sidewalk Cafe  |         41 | Pawnbroker     |          1 | Debt Collection Agency |            3 | Cigarette Retail Dealer |          104 | Manhattan |           214 |           758 | Passed Inspection |     5004 |         27548 |        3763 |         14569 |     9216 |
|     10022 | Sidewalk Cafe  |         28 | Pawnbroker     |          3 | Debt Collection Agency |            1 | Cigarette Retail Dealer |           72 | Manhattan |           131 |           419 | Passed Inspection |     5166 |         22758 |        1725 |         11798 |     9235 |
|     10032 | Sidewalk Cafe  |          6 | Pawnbroker     |          1 | Debt Collection Agency |            1 | Cigarette Retail Dealer |           53 | Manhattan |           649 |          2419 | Passed Inspection |     8846 |         38151 |        4695 |         22041 |    11415 |
|     10036 | Sidewalk Cafe  |         33 | Pawnbroker     |         32 | Debt Collection Agency |            2 | Cigarette Retail Dealer |           74 | Manhattan |           142 |           705 | Passed Inspection |     4752 |         52484 |        4547 |         29306 |    18631 |
|     10458 | Sidewalk Cafe  |          6 | Pawnbroker     |         15 | Debt Collection Agency |            1 | Cigarette Retail Dealer |           95 | Bronx     |          3107 |          7354 | Passed Inspection |    28913 |         69136 |        7326 |         41794 |    20016 |

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
source_7.csv
source_8.csv
test: test_0.csv
test_1.csv
test_2.csv
test_3.csv
test_4.csv
test_5.csv
test_6.csv
test_7.csv
test_8.csv