Task: Transform-by-output-target-schema (source dataset: commercial-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 |   ST_CASE |   VE_TOTAL |   VE_FORMS |   PVH_INVL |   PEDS |   PERNOTMVIT |   PERMVIT |   PERSONS |   COUNTY |   CITY |   DAY |   MONTH |   YEAR |   DAY_WEEK |   HOUR |   MINUTE |   NHS |   RUR_URB |   FUNC_SYS |   RD_OWNER |   ROUTE | TWAY_ID                   | TWAY_ID2   |   MILEPT |   LATITUDE |   LONGITUD |   SP_JUR |   HARM_EV |   MAN_COLL |   RELJCT1 |   RELJCT2 |   TYP_INT |   WRK_ZONE |   REL_ROAD |   LGT_COND |   WEATHER1 |   WEATHER2 |   WEATHER |   SCH_BUS |   RAIL |   NOT_HOUR |   NOT_MIN |   ARR_HOUR |   ARR_MIN |   HOSP_HR |   HOSP_MN |   CF1 |   CF2 |   CF3 |   FATALS |   DRUNK_DR | DATE       | Weekday   |
|--------:|----------:|-----------:|-----------:|-----------:|-------:|-------------:|----------:|----------:|---------:|-------:|------:|--------:|-------:|-----------:|-------:|---------:|------:|----------:|-----------:|-----------:|--------:|:--------------------------|:-----------|---------:|-----------:|-----------:|---------:|----------:|-----------:|----------:|----------:|----------:|-----------:|-----------:|-----------:|-----------:|-----------:|----------:|----------:|-------:|-----------:|----------:|-----------:|----------:|----------:|----------:|------:|------:|------:|---------:|-----------:|:-----------|:----------|
|       1 |     10051 |          2 |          2 |          0 |      0 |            0 |         5 |         5 |      109 |   3040 |     1 |       2 |   2015 |          1 |     14 |       38 |     0 |         2 |          4 |          1 |       2 | US-SR 15                  |            |     1045 |    31.8234 |   -85.9605 |        0 |        12 |          6 |         0 |         1 |         1 |          0 |          1 |          1 |          2 |          0 |         2 |         0 |      0 |         99 |        99 |         14 |        49 |        99 |        99 |     0 |     0 |     0 |        1 |          0 | 2015-02-01 | Sunday    |
|       1 |     10052 |          1 |          1 |          0 |      0 |            0 |         1 |         1 |       83 |   9997 |     9 |       2 |   2015 |          2 |      4 |       40 |     0 |         2 |          5 |          4 |       6 | HUNTSVILLE BROWNSFERRY RD |            |        0 |    34.7296 |   -86.8562 |        0 |        32 |          0 |         0 |         1 |         1 |          0 |          4 |          2 |          2 |          0 |         2 |         0 |      0 |         99 |        99 |          4 |        56 |        88 |        88 |     0 |     0 |     0 |        1 |          0 | 2015-02-09 | Monday    |
|       1 |     10053 |          1 |          1 |          0 |      0 |            0 |         3 |         3 |       37 |      0 |     1 |       2 |   2015 |          1 |     17 |       55 |     0 |         1 |          3 |          1 |       2 | US-SR 21                  |            |     1999 |    33.0383 |   -86.2256 |        0 |        35 |          0 |         0 |         1 |         1 |          0 |          4 |          2 |          2 |          0 |         2 |         0 |      0 |         99 |        99 |         18 |         6 |        99 |        99 |     0 |     0 |     0 |        1 |          0 | 2015-02-01 | Sunday    |
|       1 |     10054 |          2 |          2 |          0 |      0 |            0 |         2 |         2 |       91 |      0 |     3 |       2 |   2015 |          3 |     17 |       30 |     0 |         1 |          3 |          1 |       2 | US-SR 8                   |            |      261 |    32.4479 |   -87.9639 |        0 |        12 |          1 |         0 |         1 |         1 |          0 |          1 |          5 |          1 |          0 |         1 |         0 |      0 |         17 |        31 |         17 |        43 |        88 |        88 |     0 |     0 |     0 |        1 |          0 | 2015-02-03 | Tuesday   |
|       1 |     10055 |          1 |          1 |          0 |      1 |            1 |         1 |         1 |       89 |      0 |     4 |       2 |   2015 |          4 |      2 |       25 |     0 |         2 |          3 |          1 |       2 | US-SR 1                   |            |     3443 |    34.8679 |   -86.5714 |        0 |         8 |          0 |         0 |         1 |         1 |          0 |          1 |          2 |          1 |          0 |         1 |         0 |      0 |         88 |        88 |         88 |        88 |        88 |        88 |     0 |     0 |     0 |        1 |          0 | 2015-02-04 | Wednesday |
|       1 |     10056 |          1 |          1 |          0 |      0 |            0 |         1 |         1 |        3 |      0 |     8 |       2 |   2015 |          1 |      2 |       20 |     0 |         1 |          7 |          1 |       2 | US-SR 16                  |            |      764 |    30.5211 |   -87.4586 |        0 |        59 |          0 |         0 |         1 |         1 |          0 |          4 |          2 |          1 |          0 |         1 |         0 |      0 |         99 |        99 |          2 |        30 |        88 |        88 |     0 |     0 |     0 |        1 |          1 | 2015-02-08 | Sunday    |
|       1 |     10057 |          3 |          3 |          0 |      0 |            0 |         3 |         3 |       49 |   2564 |     4 |       2 |   2015 |          4 |     17 |       52 |     1 |         1 |          3 |          1 |       3 | SR-35                     |            |      276 |    34.4524 |   -85.7817 |        0 |        12 |          1 |         0 |         1 |         1 |          0 |          1 |          2 |          1 |          0 |         1 |         0 |      0 |         99 |        99 |         18 |         0 |        88 |        88 |     0 |     0 |     0 |        1 |          0 | 2015-02-04 | Wednesday |
|       1 |     10058 |          2 |          2 |          0 |      0 |            0 |         3 |         3 |       13 |   1460 |     8 |       2 |   2015 |          1 |     14 |       40 |     0 |         2 |          4 |          1 |       3 | SR-10                     |            |        0 |    31.8269 |   -86.6481 |        0 |         1 |          0 |         0 |         8 |         1 |          0 |          1 |          1 |          1 |          0 |         1 |         0 |      0 |         14 |        43 |         14 |        46 |        14 |        53 |     0 |     0 |     0 |        1 |          0 | 2015-02-08 | Sunday    |
|       1 |     10059 |          1 |          1 |          0 |      1 |            1 |         1 |         1 |       33 |      0 |    10 |       2 |   2015 |          3 |     22 |        0 |     1 |         1 |          3 |          1 |       3 | SR-157                    |            |      568 |    34.6532 |   -87.5282 |        0 |         8 |          0 |         0 |         1 |         1 |          0 |          1 |          2 |          1 |          0 |         1 |         0 |      0 |         22 |         4 |         22 |        13 |        22 |        46 |     0 |     0 |     0 |        1 |          0 | 2015-02-10 | Tuesday   |
|       1 |     10060 |          2 |          2 |          0 |      0 |            0 |         7 |         7 |       49 |   2564 |    10 |       2 |   2015 |          3 |     17 |       39 |     0 |         1 |          4 |          4 |       6 | MCCURDY AVE               |            |      880 |    34.5224 |   -85.8272 |        0 |        12 |          6 |         0 |         1 |         1 |          0 |          1 |          2 |         10 |          0 |        10 |         0 |      0 |         17 |        56 |         18 |        25 |        99 |        99 |     0 |     0 |     0 |        1 |          0 | 2015-02-10 | Tuesday   |


Target Schema:
| Weekday   |   DAY_WEEK_x |   STATE |   ST_CASE |   VE_TOTAL |   VE_FORMS |   PVH_INVL |   PEDS |   PERNOTMVIT |   PERMVIT |   PERSONS |   COUNTY |   CITY |   DAY |   MONTH |   YEAR |   DAY_WEEK_y |   HOUR |   MINUTE |   NHS |   RUR_URB |   FUNC_SYS |   RD_OWNER |   ROUTE | TWAY_ID         | TWAY_ID2    |   MILEPT |   LATITUDE |   LONGITUD |   SP_JUR |   HARM_EV |   MAN_COLL |   RELJCT1 |   RELJCT2 |   TYP_INT |   WRK_ZONE |   REL_ROAD |   LGT_COND |   WEATHER1 |   WEATHER2 |   WEATHER |   SCH_BUS |   RAIL |   NOT_HOUR |   NOT_MIN |   ARR_HOUR |   ARR_MIN |   HOSP_HR |   HOSP_MN |   CF1 |   CF2 |   CF3 |   FATALS |   DRUNK_DR | DATE       |
|:----------|-------------:|--------:|----------:|-----------:|-----------:|-----------:|-------:|-------------:|----------:|----------:|---------:|-------:|------:|--------:|-------:|-------------:|-------:|---------:|------:|----------:|-----------:|-----------:|--------:|:----------------|:------------|---------:|-----------:|-----------:|---------:|----------:|-----------:|----------:|----------:|----------:|-----------:|-----------:|-----------:|-----------:|-----------:|----------:|----------:|-------:|-----------:|----------:|-----------:|----------:|----------:|----------:|------:|------:|------:|---------:|-----------:|:-----------|
| Friday    |            6 |       1 |     10012 |          3 |          3 |          0 |      0 |            0 |         6 |         6 |       95 |   1500 |     9 |       1 |   2015 |            6 |      6 |       35 |     0 |         2 |          3 |          1 |       2 | US-SR 1         |             |     2944 |    34.3691 |   -86.2889 |        0 |        12 |          6 |         0 |         1 |         1 |          0 |          1 |          1 |          1 |          0 |         1 |         0 |      0 |         99 |        99 |          6 |        41 |        99 |        99 |     0 |     0 |     0 |        1 |          0 | 2015-01-09 |
| Friday    |            6 |       1 |     10018 |          1 |          1 |          0 |      0 |            0 |         2 |         2 |        1 |      0 |    16 |       1 |   2015 |            6 |     19 |       15 |     0 |         1 |          5 |          2 |       4 | CR-40           |             |        0 |    32.5243 |   -86.6721 |        0 |        42 |          0 |         0 |         1 |         1 |          0 |          4 |          2 |          1 |          0 |         1 |         0 |      0 |         99 |        99 |         19 |        35 |        99 |        99 |     0 |     0 |     0 |        1 |          1 | 2015-01-16 |
| Friday    |            6 |       1 |     10021 |          2 |          2 |          0 |      0 |            0 |         4 |         4 |      115 |      0 |    23 |       1 |   2015 |            6 |     13 |       48 |     1 |         1 |          1 |          1 |       1 | I-20            |             |     1446 |    33.566  |   -86.521  |        0 |        12 |          1 |         0 |         1 |         1 |          0 |          1 |          1 |          2 |          0 |         2 |         0 |      0 |         99 |        99 |         14 |         5 |        99 |        99 |    27 |     0 |     0 |        1 |          0 | 2015-01-23 |
| Friday    |            6 |       1 |     10024 |          1 |          1 |          0 |      0 |            0 |         1 |         1 |        5 |      0 |     2 |       1 |   2015 |            6 |      6 |        0 |     0 |         1 |          7 |          2 |       4 | CR-32           |             |        0 |    31.8395 |   -85.2207 |        0 |        42 |          0 |         0 |         1 |         1 |          0 |          5 |          4 |          1 |          0 |         1 |         0 |      0 |         99 |        99 |          6 |        25 |        99 |        99 |     0 |     0 |     0 |        1 |          0 | 2015-01-02 |
| Friday    |            6 |       1 |     10029 |          1 |          1 |          0 |      0 |            0 |         1 |         1 |       69 |      0 |    23 |       1 |   2015 |            6 |      5 |       40 |     0 |         1 |          3 |          1 |       2 | US-SR 12        | THOMPSON RD |     2228 |    31.1613 |   -85.1906 |        0 |        59 |          0 |         0 |         3 |         3 |          0 |          4 |          2 |          2 |          0 |         2 |         0 |      0 |         99 |        99 |          5 |        52 |        88 |        88 |     0 |     0 |     0 |        1 |          0 | 2015-01-23 |
| Friday    |            6 |       1 |     10033 |          1 |          1 |          0 |      0 |            0 |         2 |         2 |      123 |     60 |    23 |       1 |   2015 |            6 |     21 |       22 |     0 |         1 |          6 |          4 |       6 | CR-40           |             |        0 |    32.8764 |   -85.8776 |        0 |        42 |          0 |         0 |         1 |         1 |          0 |          4 |          3 |          2 |          0 |         2 |         0 |      0 |         99 |        99 |         21 |        28 |        88 |        88 |     0 |     0 |     0 |        2 |          1 | 2015-01-23 |
| Monday    |            7 |       1 |     10010 |          2 |          2 |          0 |      0 |            0 |         2 |         2 |       33 |      0 |     5 |       1 |   2015 |            2 |     18 |       45 |     0 |         1 |          4 |          1 |       3 | SR-184          |             |       34 |    34.7584 |   -87.6075 |        0 |        12 |          2 |         0 |         1 |         1 |          0 |          1 |          2 |          1 |          0 |         1 |         0 |      0 |         99 |        99 |         19 |         1 |        99 |        99 |     0 |     0 |     0 |        1 |          0 | 2015-01-05 |
| Monday    |            7 |       1 |     10019 |          1 |          1 |          0 |      0 |            0 |         1 |         1 |      121 |      0 |    19 |       1 |   2015 |            2 |      1 |        0 |     0 |         1 |          6 |          2 |       4 | CR-ODENA ROAD N |             |        0 |    33.2293 |   -86.2693 |        0 |         1 |          0 |         0 |         1 |         1 |          0 |          1 |          2 |          1 |          0 |         1 |         0 |      0 |         88 |        88 |         88 |        88 |        88 |        88 |     0 |     0 |     0 |        1 |          0 | 2015-01-19 |
| Monday    |            7 |       1 |     10022 |          1 |          1 |          0 |      0 |            0 |         2 |         2 |      127 |      0 |    26 |       1 |   2015 |            2 |      6 |       15 |     1 |         1 |          2 |          1 |       1 | I-22            |             |      585 |    33.8402 |   -87.3316 |        0 |        52 |          0 |         0 |         1 |         1 |          0 |          3 |          2 |          1 |          0 |         1 |         0 |      0 |         99 |        99 |          6 |        30 |        99 |        99 |     0 |     0 |     0 |        1 |          0 | 2015-01-26 |
| Monday    |            7 |       1 |     10023 |          1 |          1 |          0 |      0 |            0 |         1 |         1 |       11 |      0 |    12 |       1 |   2015 |            2 |     21 |       20 |     0 |         1 |          4 |          1 |       3 | SR-110          |             |      210 |    32.2172 |   -85.9188 |        0 |        42 |          0 |         0 |         1 |         1 |          0 |          4 |          2 |          5 |          0 |         5 |         0 |      0 |         99 |        99 |         21 |        25 |        88 |        88 |     0 |     0 |     0 |        1 |          1 | 2015-01-12 |

Return only the final code in markdown codeblock format, without any additional text or explanation. 



target: target.csv
train: source_0.csv
test: test_0.csv