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:
|         track_id |   dummy |
|-----------------:|--------:|
|      2.13023e+06 |       1 |
|      1.33449e+06 |       1 |
| 248396           |       1 |
|      2.63682e+06 |       1 |
|      2.07724e+06 |       1 |
|      1.76707e+06 |       1 |
|      2.80895e+06 |       1 |
|      2.65487e+06 |       1 |
| 695103           |       1 |
|      2.1753e+06  |       1 |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|   index_playlist |      playlist_id |
|-----------------:|-----------------:|
|             4462 |      2.56944e+06 |
|            37587 |      1.01512e+07 |
|            19329 |      5.90353e+06 |
|             1790 | 551237           |
|            37211 |      1.00963e+07 |
|            37113 |      1.00786e+07 |
|            37002 |      1.00618e+07 |
|            26106 |      7.29604e+06 |
|            32691 |      8.42595e+06 |
|              213 |  30887           |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
|      playlist_id |         track_id |   interaction |
|-----------------:|-----------------:|--------------:|
| 574797           |      1.69072e+06 |             1 |
|      1.05004e+07 |      2.01286e+06 |             1 |
|      6.0743e+06  | 279781           |             1 |
|      7.9114e+06  |      2.67987e+06 |             1 |
|      5.73128e+06 |      1.61529e+06 |             1 |
|      2.33246e+06 |      3.73754e+06 |             1 |
|      8.80316e+06 |      2.81189e+06 |             1 |
|      2.90263e+06 |      3.41674e+06 |             1 |
|      7.75113e+06 |      3.54908e+06 |             1 |
|      1.16481e+07 |      1.9618e+06  |             1 |


Table #4
Filename: source_3.csv
Sample Rows in Markdown:
|   index_track |         track_id |
|--------------:|-----------------:|
|         69158 |      2.53708e+06 |
|         27172 |      1.38479e+06 |
|         99805 |      3.14501e+06 |
|         14258 |      1.87339e+06 |
|         90979 |      1.80592e+06 |
|         97409 |      3.13749e+06 |
|         69689 |      2.53816e+06 |
|         28597 |      2.43634e+06 |
|         94051 |      1.81617e+06 |
|         23953 | 851460           |


Target Schema:
|    track_id |   dummy |   playlist_id |   interaction |   index_playlist |   index_track |
|------------:|--------:|--------------:|--------------:|-----------------:|--------------:|
| 3.09127e+06 |       1 |   8.93522e+06 |             1 |            36157 |         82302 |
| 2.99424e+06 |       1 |   8.28676e+06 |             1 |            31967 |         41660 |
| 2.99424e+06 |       1 |   1.09168e+07 |             1 |            41938 |         41660 |
| 2.87126e+06 |       1 |   7.24622e+06 |             1 |            25887 |         96183 |
| 2.37449e+06 |       1 |   5.62364e+06 |             1 |            17804 |          5079 |
| 2.37449e+06 |       1 |   6.05232e+06 |             1 |            20038 |          5079 |
| 1.07441e+06 |       1 |   4.73352e+06 |             1 |            13536 |          8957 |
| 1.07441e+06 |       1 |   5.45423e+06 |             1 |            16970 |          8957 |
| 2.70965e+06 |       1 |   1.17463e+07 |             1 |            45571 |         32882 |
| 2.93382e+06 |       1 |   7.54198e+06 |             1 |            28025 |         18402 |

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