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 | gender   |   age |   occupation | zip        |
|----------:|:---------|------:|-------------:|:-----------|
|      4354 | M        |    35 |           14 | 78611      |
|      2313 | F        |    50 |            6 | 48103-4711 |
|      5333 | F        |    25 |            7 | 02332      |
|      1863 | M        |    18 |            4 | 90048      |
|      5495 | F        |    18 |            4 | 95076      |
|      3032 | M        |    25 |            0 | 47303      |
|        65 | M        |    35 |           12 | 55803      |
|      5521 | F        |    25 |            6 | 02118      |
|       521 | M        |    56 |            7 | 55105      |
|      4451 | M        |    25 |           14 | 30101      |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|   movie_id | title                                     | genres                    |
|-----------:|:------------------------------------------|:--------------------------|
|       2380 | Police Academy 3: Back in Training (1986) | Comedy                    |
|        832 | Ransom (1996)                             | Drama|Thriller            |
|       2759 | Dick (1999)                               | Comedy                    |
|       1007 | Apple Dumpling Gang, The (1975)           | Children's|Comedy|Western |
|       3232 | Seven Chances (1925)                      | Comedy                    |
|       2949 | Dr. No (1962)                             | Action                    |
|       3283 | Minnie and Moskowitz (1971)               | Action                    |
|        647 | Courage Under Fire (1996)                 | Drama|War                 |
|       2457 | Running Scared (1986)                     | Action|Comedy             |
|       1976 | Friday the 13th Part 3: 3D (1982)         | Horror                    |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
|   user_id |   movie_id |   rating |   timestamp |
|----------:|-----------:|---------:|------------:|
|      1074 |       3789 |        3 | 9.74941e+08 |
|      2117 |       1270 |        4 | 9.74649e+08 |
|      2820 |       1376 |        4 | 9.72671e+08 |
|      2453 |        144 |        3 | 9.82136e+08 |
|      1889 |       3355 |        3 | 9.8909e+08  |
|      1449 |        719 |        1 | 9.76316e+08 |
|      1199 |       1704 |        4 | 9.74847e+08 |
|      2529 |        674 |        2 | 9.74063e+08 |
|      3605 |       2710 |        1 | 9.66615e+08 |
|      4979 |        111 |        4 | 9.62603e+08 |


Target Schema:
|   movie_id |   user_id |   rating |   timestamp |   gender |   age |   occupation |   zip |   title_x |   genres_x | title_y                            | genres_y                     |
|-----------:|----------:|---------:|------------:|---------:|------:|-------------:|------:|----------:|-----------:|:-----------------------------------|:-----------------------------|
|          1 |         8 |        8 |           8 |        8 |     8 |            8 |     8 |         8 |          8 | Toy Story (1995)                   | Animation|Children's|Comedy  |
|          2 |         5 |        5 |           5 |        5 |     5 |            5 |     5 |         5 |          5 | Jumanji (1995)                     | Adventure|Children's|Fantasy |
|          5 |         1 |        1 |           1 |        1 |     1 |            1 |     1 |         1 |          1 | Father of the Bride Part II (1995) | Comedy                       |
|          7 |         4 |        4 |           4 |        4 |     4 |            4 |     4 |         4 |          4 | Sabrina (1995)                     | Comedy|Romance               |
|         10 |         5 |        5 |           5 |        5 |     5 |            5 |     5 |         5 |          5 | GoldenEye (1995)                   | Action|Adventure|Thriller    |
|         12 |         2 |        2 |           2 |        2 |     2 |            2 |     2 |         2 |          2 | Dracula: Dead and Loving It (1995) | Comedy|Horror                |
|         13 |         2 |        2 |           2 |        2 |     2 |            2 |     2 |         2 |          2 | Balto (1995)                       | Animation|Children's         |
|         15 |         2 |        2 |           2 |        2 |     2 |            2 |     2 |         2 |          2 | Cutthroat Island (1995)            | Action|Adventure|Romance     |
|         20 |         3 |        3 |           3 |        3 |     3 |            3 |     3 |         3 |          3 | Money Train (1995)                 | Action                       |
|         21 |         5 |        5 |           5 |        5 |     5 |            5 |     5 |         5 |          5 | Get Shorty (1995)                  | Action|Comedy|Drama          |

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