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:
|   Slice n° |   X |   Y |   Distance |   Pixel Value |   ok_col_names |   ok_col_num |   ok_row_num | cop_name   |   day | fname    |
|-----------:|----:|----:|-----------:|--------------:|---------------:|-------------:|-------------:|:-----------|------:|:---------|
|         29 |  51 |  97 |      0.129 |           211 |              1 |            0 |            0 | 26_2C      |    17 | 26_2C_17 |
|          6 |  28 |  23 |      0.645 |           246 |              1 |            0 |            0 | 18_5D      |    13 | 18_5D_13 |
|          1 |  18 |  32 |     -1     |           149 |              1 |            0 |            0 | 52_1D      |    17 | 52_1D_17 |
|         42 |  35 |  25 |      0     |           172 |              0 |            0 |            0 | 07_5B      |     9 | 07_5B_9  |
|         45 |  80 |  47 |      0.288 |           133 |              0 |            0 |            0 | 41_6C      |     5 | 41_6C_5  |
|         32 |  27 |  34 |      0.785 |           126 |              0 |            0 |            0 | 23_3A      |     5 | 23_3A_5  |
|         25 |  50 |  91 |      0     |           119 |              1 |            0 |            0 | 70_6D      |     9 | 70_6D_9  |
|         21 |  30 |  80 |      0.532 |           181 |              0 |            0 |            0 | 55_4B      |     7 | 55_4B_7  |
|         57 |  84 |  41 |      0.532 |           143 |              1 |            0 |            0 | 62_4B      |     9 | 62_4B_9  |
|         26 |  44 |  75 |      1.833 |           141 |              0 |            0 |            0 | 34_5D      |     5 | 34_5D_5  |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
|   ï»¿index | cop   |   day | fname   | by   |   Ok? | remarks   |
|-----------:|:------|------:|:--------|:-----|------:|:----------|
|          1 | 01_1D |     5 | 01_1D_5 | DB   |     0 |           |
|         10 | 01_2B |     5 | 01_2B_5 | MS   |     0 |           |
|         19 | 01_2C |     5 | 01_2C_5 | MS   |     0 |           |
|         28 | 01_3D |     5 | 01_3D_5 | MS   |     0 |           |
|         37 | 01_4A |     5 | 01_4A_5 | MS   |     0 |           |
|         46 | 01_4D |     5 | 01_4D_5 | MS   |     0 |           |
|         55 | 01_6C |     5 | 01_6C_5 | MS   |     0 |           |
|         64 | 01_6D |     5 | 01_6D_5 | MS   |     0 |           |
|         73 | 02_1C |     5 | 02_1C_5 | MS   |     0 |           |
|         82 | 02_3B |     5 | 02_3B_5 | MS   |     0 |           |


Target Schema:
| fname    |   row_count |
|:---------|------------:|
| 01_1D_11 |          20 |
| 01_1D_13 |          22 |
| 01_1D_15 |          23 |
| 01_1D_17 |          24 |
| 01_1D_5  |          15 |
| 01_1D_7  |          22 |
| 01_1D_9  |          25 |
| 01_2B_11 |          14 |
| 01_2B_5  |          20 |
| 01_2B_7  |          26 |

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