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 |
|-----------------:|-------------:|--------------------:|------------:|
|      2.33223e+06 |         4957 |                  12 |           1 |
|      2.36086e+06 |        48018 |                   5 |           1 |
|      2.9587e+06  |        33080 |                  25 |           0 |
|      1.97733e+06 |        25890 |                   2 |           1 |
|      3.3558e+06  |         8174 |                  12 |           1 |
|      3.21058e+06 |         5025 |                  22 |           1 |
| 509352           |        30391 |                   4 |           1 |
|      3.34963e+06 |        15613 |                   2 |           1 |
| 285409           |         5794 |                  12 |           0 |
|      1.51178e+06 |        46572 |                   4 |           1 |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|         order_id |   product_id |   add_to_cart_order |   reordered |
|-----------------:|-------------:|--------------------:|------------:|
|      2.05734e+06 |        22533 |                   5 |           0 |
|  80130           |        36011 |                   7 |           1 |
|      1.18932e+06 |        14778 |                  35 |           0 |
| 782701           |        13212 |                  10 |           1 |
|      1.68394e+06 |        21903 |                   5 |           1 |
|      1.03963e+06 |        41290 |                   2 |           1 |
|      1.90646e+06 |         4920 |                  12 |           0 |
|      1.50954e+06 |        32691 |                   6 |           0 |
| 216596           |        42804 |                  10 |           0 |
|      1.20792e+06 |        33129 |                  11 |           0 |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
|   order_id |   user_id | eval_set   |   order_number |   order_dow |   order_hour_of_day |   days_since_prior_order |
|-----------:|----------:|:-----------|---------------:|------------:|--------------------:|-------------------------:|
|    1573325 |    179064 | prior      |              4 |           1 |                  14 |                       30 |
|    2786162 |     91986 | prior      |             35 |           2 |                  15 |                        4 |
|    1171597 |    103630 | prior      |              3 |           5 |                  10 |                       23 |
|    1995311 |    196195 | prior      |              8 |           5 |                  13 |                        5 |
|     981826 |      4860 | prior      |             17 |           4 |                   9 |                        7 |
|      10665 |     80231 | prior      |             52 |           4 |                   9 |                        3 |
|    3005592 |    201248 | prior      |             38 |           3 |                  17 |                        2 |
|    2485624 |    174185 | prior      |              9 |           6 |                  18 |                        2 |
|    1067844 |     61301 | prior      |              2 |           5 |                   9 |                        5 |
|    3377142 |     91122 | prior      |             19 |           3 |                   9 |                       14 |


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 |
|----------:|-------------:|-------------:|-----------------:|--------------:|----------------------:|---------------------------:|---------------:|----------------------:|--------------:|--------------:|-------------:|-------------:|-----------------:|--------------:|----------------------:|---------------------------:|---------------:|----------------------:|------------:|
|     11050 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |             1 |             0 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |           1 |
|     16447 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |             1 |             0 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |           1 |
|     37911 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |             1 |             0 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |           1 |
|     41370 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |             1 |             1 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |           1 |
|     76762 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |             1 |             1 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |           1 |
|     90709 |            1 |            1 |                1 |             1 |                     1 |                          0 |              1 |                     1 |             1 |             0 |            1 |            1 |                1 |             1 |                     1 |                          0 |              1 |                     1 |           1 |
|     95503 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |             1 |             0 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |           1 |
|    132543 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |             1 |             0 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |           1 |
|    140605 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |             1 |             1 |            1 |            1 |                1 |             1 |                     1 |                          1 |              1 |                     1 |           1 |
|    151030 |            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