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    |
|-----------:|----:|----:|-----------:|--------------:|---------------:|-------------:|-------------:|:-----------|------:|:---------|
|         44 |  86 |  39 |      0     |           113 |              1 |            0 |            0 | 51_5B      |     9 | 51_5B_9  |
|         60 |  27 |  20 |      3.329 |           160 |              0 |            0 |            0 | 05_4B      |     7 | 05_4B_7  |
|         48 |  62 |  90 |      0.129 |           174 |              0 |            0 |            0 | 35_4D      |     5 | 35_4D_5  |
|         31 |  97 |  77 |      0.129 |           106 |              1 |            0 |            0 | 22_6B      |    15 | 22_6B_15 |
|         39 |  23 |  46 |      0     |           211 |              1 |            0 |            0 | 37_3C      |    13 | 37_3C_13 |
|         55 |  75 |  70 |      0.465 |           175 |              0 |            0 |            0 | 27_4B      |     5 | 27_4B_5  |
|         43 |  88 |  26 |      0     |           136 |              1 |            0 |            0 | 24_2B      |    15 | 24_2B_15 |
|         26 |  51 |  76 |      0     |           135 |              1 |            0 |            0 | 09_6C      |    17 | 09_6C_17 |
|          5 |  97 |  77 |      0     |           121 |              1 |            0 |            0 | 40_6D      |    11 | 40_6D_11 |
|         37 |  63 |  85 |      0     |           217 |              1 |            0 |            0 | 52_1C      |    11 | 52_1C_11 |


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 |          25 |
| 01_1D_13 |          22 |
| 01_1D_15 |          23 |
| 01_1D_17 |          19 |
| 01_1D_5  |          24 |
| 01_1D_7  |          24 |
| 01_1D_9  |          20 |
| 01_2B_11 |          20 |
| 01_2B_5  |          21 |
| 01_2B_7  |          25 |

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