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:
|   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 |


Table #3
Filename: source_2.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                    |


Target Schema:
| title                                        |   user_id |   movie_id_x |   rating |   timestamp |   gender |   age |   occupation |   zip |   genres_x |   movie_id_y | genres_y                            |
|:---------------------------------------------|----------:|-------------:|---------:|------------:|---------:|------:|-------------:|------:|-----------:|-------------:|:------------------------------------|
| 101 Dalmatians (1996)                        |         5 |            5 |        5 |           5 |        5 |     5 |            5 |     5 |          5 |         1367 | Children's|Comedy                   |
| 12 Angry Men (1957)                          |         4 |            4 |        4 |           4 |        4 |     4 |            4 |     4 |          4 |         1203 | Drama                               |
| 20,000 Leagues Under the Sea (1954)          |         4 |            4 |        4 |           4 |        4 |     4 |            4 |     4 |          4 |         1019 | Adventure|Children's|Fantasy|Sci-Fi |
| 200 Cigarettes (1999)                        |         2 |            2 |        2 |           2 |        2 |     2 |            2 |     2 |          2 |         2504 | Comedy|Drama                        |
| 28 Days (2000)                               |         6 |            6 |        6 |           6 |        6 |     6 |            6 |     6 |          6 |         3534 | Comedy                              |
| 42 Up (1998)                                 |         2 |            2 |        2 |           2 |        2 |     2 |            2 |     2 |          2 |         3077 | Documentary                         |
| 8 1/2 (1963)                                 |         1 |            1 |        1 |           1 |        1 |     1 |            1 |     1 |          1 |         1251 | Drama                               |
| Abbott and Costello Meet Frankenstein (1948) |         2 |            2 |        2 |           2 |        2 |     2 |            2 |     2 |          2 |         3928 | Comedy|Horror                       |
| Ace Ventura: Pet Detective (1994)            |         8 |            8 |        8 |           8 |        8 |     8 |            8 |     8 |          8 |          344 | Comedy                              |
| Action Jackson (1988)                        |         2 |            2 |        2 |           2 |        2 |     2 |            2 |     2 |          2 |         3710 | Action|Comedy                       |

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