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:
|   Purchase ID | SN            |   Age | Gender   |   Item ID | Item Name                   |   Price |
|--------------:|:--------------|------:|:---------|----------:|:----------------------------|--------:|
|           390 | Asur53        |    26 | Male     |        75 | Brutality Ivory Warmace     |    2.42 |
|           391 | Alarap40      |    18 | Male     |        20 | Netherbane                  |    3.27 |
|           392 | Sida61        |    20 | Female   |       181 | Reaper's Toll               |    1.66 |
|           393 | Hiarideu73    |    20 | Male     |        54 | Eternal Cleaver             |    2.5  |
|           394 | Lassassasda30 |    12 | Male     |        60 | Wolf                        |    3.54 |
|           395 | Ennoncil86    |    17 | Male     |       152 | Darkheart                   |    1.74 |
|           396 | Siralsudeu54  |    20 | Male     |       131 | Fury                        |    1.44 |
|           397 | Eusri26       |    25 | Male     |       100 | Blindscythe                 |    3.27 |
|           398 | Ardcil81      |    34 | Male     |        96 | Blood-Forged Skeletal Spine |    3.09 |
|           399 | Marilsasya33  |    19 | Male     |       143 | Frenzied Scimitar           |    1.56 |


Target Schema:
|   Purchase Count |   SN |   Age_x |   Gender |   Item ID_x |   Item Name |   Price |   Purchase ID_x |   Age_y |   Item ID_y |   Average Purchase Price |   Purchase ID_y |   Age |   Item ID |   Total Purchase Value |
|-----------------:|-----:|--------:|---------:|------------:|------------:|--------:|----------------:|--------:|------------:|-------------------------:|----------------:|------:|----------:|-----------------------:|
|                3 |    3 |       3 |        3 |           3 |           3 |       3 |          46     |       7 |     63.3333 |                  3.35667 |             138 |    21 |       190 |                  10.07 |
|                6 |    6 |       6 |        6 |           6 |           6 |       6 |         204.5   |       8 |     97.6667 |                  2.69333 |            1227 |    48 |       586 |                  16.16 |
|                5 |    5 |       5 |        5 |           5 |           5 |       5 |          84     |      10 |     86.4    |                  3.81    |             420 |    50 |       432 |                  19.05 |
|                3 |    3 |       3 |        3 |           3 |           3 |       3 |         162.667 |      11 |    100      |                  2.49333 |             488 |    33 |       300 |                   7.48 |
|                1 |    1 |       1 |        1 |           1 |           1 |       1 |          56     |      12 |    108      |                  3.53    |              56 |    12 |       108 |                   3.53 |
|                3 |    3 |       3 |        3 |           3 |           3 |       3 |         169     |      13 |    105.333  |                  2.41    |             507 |    39 |       316 |                   7.23 |
|               15 |   15 |      15 |       15 |          15 |          15 |      15 |         238.133 |      15 |     93.4    |                  3.34867 |            3572 |   225 |      1401 |                  50.23 |
|               16 |   16 |      16 |       16 |          16 |          16 |      16 |         228.812 |      16 |     84.125  |                  3.01875 |            3661 |   256 |      1346 |                  48.3  |
|               13 |   13 |      13 |       13 |          13 |          13 |      13 |         218.077 |      17 |    122      |                  2.98154 |            2835 |   221 |      1586 |                  38.76 |
|               14 |   14 |      14 |       14 |          14 |          14 |      14 |         239.857 |      18 |     81.3571 |                  2.81929 |            3358 |   252 |      1139 |                  39.47 |

Return only the final code in markdown codeblock format, without any additional text or explanation. 



target: target.csv
train: source_0.csv
test: test_0.csv