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    |
|-----------:|----:|----:|-----------:|--------------:|---------------:|-------------:|-------------:|:-----------|------:|:---------|
|          4 |  56 |  92 |      3.694 |           172 |              0 |            0 |            0 | 31_5B      |     7 | 31_5B_7  |
|         43 |  23 |  79 |      0.182 |           144 |              0 |            0 |            0 | 31_4B      |     5 | 31_4B_5  |
|          8 |  79 |  60 |      0     |           112 |              0 |            0 |            0 | 29_1A      |    13 | 29_1A_13 |
|         47 |  39 | 108 |      0.129 |           142 |              1 |            0 |            0 | 22_6B      |    11 | 22_6B_11 |
|         48 |  17 |  73 |      0     |           170 |              1 |            0 |            0 | 36_6A      |    17 | 36_6A_17 |
|         59 |  68 |  96 |      0     |           139 |              1 |            0 |            0 | 39_5B      |    17 | 39_5B_17 |
|         44 |  86 |  29 |      1.11  |           219 |              1 |            0 |            0 | 47_4C      |    11 | 47_4C_11 |
|         14 |  84 |  26 |      1.918 |           133 |              1 |            0 |            0 | 41_1A      |    15 | 41_1A_15 |
|         48 |  17 |  52 |      0.288 |           128 |              0 |            0 |            0 | 15_6D      |     5 | 15_6D_5  |
|         61 |  49 |  94 |      0     |           144 |              0 |            0 |            0 | 42_2B      |     5 | 42_2B_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 |          24 |
| 01_1D_13 |          25 |
| 01_1D_15 |          25 |
| 01_1D_17 |          22 |
| 01_1D_5  |          18 |
| 01_1D_7  |          19 |
| 01_1D_9  |          20 |
| 01_2B_11 |          21 |
| 01_2B_5  |          17 |
| 01_2B_7  |          18 |

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