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:
|         order_id |   product_id |   add_to_cart_order |   reordered |
|-----------------:|-------------:|--------------------:|------------:|
| 870271           |        47209 |                  19 |           1 |
|      3.03141e+06 |        15366 |                  12 |           1 |
|      3.1838e+06  |        42438 |                  11 |           1 |
|      2.62404e+06 |        14197 |                  16 |           0 |
| 832587           |        33655 |                   3 |           1 |
|      3.3417e+06  |        25581 |                   1 |           1 |
| 587472           |        20794 |                   8 |           1 |
|      2.14577e+06 |        36772 |                   8 |           1 |
| 264988           |         8475 |                   9 |           1 |
|  51800           |        42342 |                  11 |           0 |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|   order_id |   user_id | eval_set   |   order_number |   order_dow |   order_hour_of_day | days_since_prior_order   |
|-----------:|----------:|:-----------|---------------:|------------:|--------------------:|:-------------------------|
|     669089 |    121223 | prior      |              3 |           3 |                   8 | 8.0                      |
|    2948289 |     99793 | prior      |              5 |           1 |                  15 | 7.0                      |
|     343907 |     46874 | prior      |              5 |           6 |                  14 | 8.0                      |
|    2097833 |      1219 | prior      |             22 |           1 |                  10 | 10.0                     |
|    3096987 |     59746 | prior      |              1 |           0 |                  17 |                          |
|     408767 |      5651 | prior      |             24 |           4 |                  22 | 3.0                      |
|     293071 |    119455 | prior      |             22 |           1 |                   9 | 12.0                     |
|     770255 |     55973 | prior      |             54 |           0 |                  13 | 1.0                      |
|     966075 |     46398 | prior      |              4 |           1 |                  20 | 0.0                      |
|    1335920 |     37762 | prior      |             35 |           5 |                   9 | 8.0                      |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
|         order_id |   product_id |   add_to_cart_order |   reordered |
|-----------------:|-------------:|--------------------:|------------:|
| 818705           |        36929 |                   1 |           1 |
|      2.40836e+06 |        29228 |                   1 |           0 |
|      2.37528e+06 |         3704 |                  13 |           1 |
|      1.07611e+06 |          325 |                   4 |           1 |
|      2.20068e+06 |        16797 |                   8 |           1 |
|      1.13574e+06 |        21616 |                  14 |           1 |
|      1.07658e+06 |         9755 |                  11 |           0 |
| 891540           |        23375 |                   6 |           1 |
|      3.03506e+06 |        48812 |                  31 |           1 |
|      2.10537e+06 |        48094 |                  14 |           0 |


Target Schema:
|   user_id |   order_id_x |   eval_set_x |   order_number_x |   order_dow_x |   order_hour_of_day_x |   days_since_prior_order_x |   product_id_x |   add_to_cart_order_x |   reordered_x |   reordered_y |   order_id_y |   eval_set_y |   order_number_y |   order_dow_y |   order_hour_of_day_y |   days_since_prior_order_y |   product_id_y |   add_to_cart_order_y |   reordered |   order_id |
|----------:|-------------:|-------------:|-----------------:|--------------:|----------------------:|---------------------------:|---------------:|----------------------:|--------------:|--------------:|-------------:|-------------:|-----------------:|--------------:|----------------------:|---------------------------:|---------------:|----------------------:|------------:|-----------:|
|      8756 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |             1 |             1 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |           1 |          1 |
|     28244 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |             1 |             0 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |           1 |          1 |
|     51753 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |             1 |             1 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |           1 |          1 |
|     65538 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |             1 |             0 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |           1 |          1 |
|     93415 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |             1 |             0 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |           1 |          1 |
|    106804 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |             1 |             1 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |           1 |          1 |
|    120905 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |             1 |             1 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |           1 |          1 |
|    128257 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |             1 |             1 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |           1 |          1 |
|    140857 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |             1 |             1 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |           1 |          1 |
|    165081 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |             1 |             1 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |           1 |          1 |

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
test: test_0.csv
test_1.csv
test_2.csv