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:
|   user_id |   age | gender   | occupation    |   zip |
|----------:|------:|:---------|:--------------|------:|
|         1 |    24 | M        | technician    | 85711 |
|         2 |    53 | F        | other         | 94043 |
|         3 |    23 | M        | writer        | 32067 |
|         4 |    24 | M        | technician    | 43537 |
|         5 |    33 | F        | other         | 15213 |
|         6 |    42 | M        | executive     | 98101 |
|         7 |    57 | M        | administrator | 91344 |
|         8 |    36 | M        | administrator |  5201 |
|         9 |    29 | M        | student       |  1002 |
|        10 |    53 | M        | lawyer        | 90703 |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|   user_id |   movie_id |   rating |   timestamp |
|----------:|-----------:|---------:|------------:|
|       472 |        161 |        5 | 8.75982e+08 |
|       648 |       1176 |        1 | 8.84628e+08 |
|       201 |        583 |        1 | 8.84112e+08 |
|       911 |        102 |        3 | 8.92841e+08 |
|       683 |        588 |        4 | 8.93287e+08 |
|       499 |         97 |        4 | 8.85599e+08 |
|       854 |       1086 |        3 | 8.82812e+08 |
|       885 |        393 |        3 | 8.85714e+08 |
|       130 |        681 |        3 | 8.75801e+08 |
|       833 |         56 |        4 | 8.75123e+08 |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
|   movie_id | movie_title                                   |   year |
|-----------:|:----------------------------------------------|-------:|
|          1 | Toy Story                                     |   1995 |
|          2 | GoldenEye                                     |   1995 |
|          3 | Four Rooms                                    |   1995 |
|          4 | Get Shorty                                    |   1995 |
|          5 | Copycat                                       |   1995 |
|          6 | Shanghai Triad (Yao a yao yao dao waipo qiao) |   1995 |
|          7 | Twelve Monkeys                                |   1995 |
|          8 | Babe                                          |   1995 |
|          9 | Dead Man Walking                              |   1995 |
|         10 | Richard III                                   |   1995 |


Target Schema:
|   movie_id |   movie_title_x |   year_x |   user_id |   rating |   timestamp |   age |   gender |   occupation |   zip | movie_title_y                                 |   year_y |
|-----------:|----------------:|---------:|----------:|---------:|------------:|------:|---------:|-------------:|------:|:----------------------------------------------|---------:|
|          1 |             208 |      208 |       208 |      208 |         208 |   208 |      208 |          208 |   208 | Toy Story                                     |     1995 |
|          2 |              59 |       59 |        59 |       59 |          59 |    59 |       59 |           59 |    59 | GoldenEye                                     |     1995 |
|          3 |              47 |       47 |        47 |       47 |          47 |    47 |       47 |           47 |    47 | Four Rooms                                    |     1995 |
|          4 |              97 |       97 |        97 |       97 |          97 |    97 |       97 |           97 |    97 | Get Shorty                                    |     1995 |
|          5 |              48 |       48 |        48 |       48 |          48 |    48 |       48 |           48 |    48 | Copycat                                       |     1995 |
|          6 |              14 |       14 |        14 |       14 |          14 |    14 |       14 |           14 |    14 | Shanghai Triad (Yao a yao yao dao waipo qiao) |     1995 |
|          7 |             203 |      203 |       203 |      203 |         203 |   203 |      203 |          203 |   203 | Twelve Monkeys                                |     1995 |
|          8 |             113 |      113 |       113 |      113 |         113 |   113 |      113 |          113 |   113 | Babe                                          |     1995 |
|          9 |             133 |      133 |       133 |      133 |         133 |   133 |      133 |          133 |   133 | Dead Man Walking                              |     1995 |
|         10 |              39 |       39 |        39 |       39 |          39 |    39 |       39 |           39 |    39 | Richard III                                   |     1995 |

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