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:
|   ï»¿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 |           |


Table #2
Filename: source_1.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    |
|-----------:|----:|----:|-----------:|--------------:|---------------:|-------------:|-------------:|:-----------|------:|:---------|
|         60 |  33 |  64 |      1.168 |           161 |              1 |            0 |            0 | 46_4D      |    17 | 46_4D_17 |
|         21 |  94 |  28 |      1.217 |           156 |              0 |            0 |            0 | 27_4D      |     5 | 27_4D_5  |
|         34 |  48 |  26 |      6.305 |           140 |              0 |            0 |            0 | 21_1D      |     5 | 21_1D_5  |
|         20 |  38 |  92 |      0     |           111 |              1 |            0 |            0 | 68_1A      |    13 | 68_1A_13 |
|         36 |  49 |  83 |      0     |           216 |              1 |            0 |            0 | 42_2B      |    13 | 42_2B_13 |
|         56 |  91 |  28 |      0     |           146 |              1 |            0 |            0 | 10_5C      |    13 | 10_5C_13 |
|         40 |  38 |  84 |      0     |           147 |              0 |            0 |            0 | 50_5C      |     5 | 50_5C_5  |
|         28 |  25 |  91 |      0.288 |           129 |              1 |            0 |            0 | 32_2A      |    17 | 32_2A_17 |
|         60 |   6 |  52 |      0.129 |           185 |              1 |            0 |            0 | 66_5D      |    17 | 66_5D_17 |
|         56 |  15 |  42 |      4.747 |           125 |              0 |            0 |            0 | 26_1B      |     9 | 26_1B_9  |


Target Schema:
| fname    |   row_count |
|:---------|------------:|
| 01_1D_11 |          23 |
| 01_1D_13 |          28 |
| 01_1D_15 |          29 |
| 01_1D_17 |          21 |
| 01_1D_5  |          15 |
| 01_1D_7  |          22 |
| 01_1D_9  |          23 |
| 01_2B_11 |          18 |
| 01_2B_5  |          18 |
| 01_2B_7  |          17 |

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