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:
| datetime   | station     | obs_type   |   obs_value |   TMAX_F |   month | country_code   |
|:-----------|:------------|:-----------|------------:|---------:|--------:|:---------------|
| 1866-01-07 | CA006158350 | TMAX       |       -21.1 |    -5.98 |       1 | CA             |
| 1866-01-08 | CA006110549 | TMAX       |       -16.7 |     1.94 |       1 | CA             |
| 1866-02-15 | CA006110549 | TMAX       |       -16.7 |     1.94 |       2 | CA             |
| 1866-01-06 | CA006110549 | TMAX       |       -16.1 |     3.02 |       1 | CA             |
| 1866-01-14 | CA006158350 | TMAX       |       -16.1 |     3.02 |       1 | CA             |
| 1866-01-15 | CA006150689 | TMAX       |       -16.1 |     3.02 |       1 | CA             |
| 1866-01-08 | CA006150689 | TMAX       |       -16.1 |     3.02 |       1 | CA             |
| 1866-02-16 | CA006148100 | TMAX       |       -15.6 |     3.92 |       2 | CA             |
| 1866-12-20 | CA006106362 | TMAX       |       -15.6 |     3.92 |      12 | CA             |
| 1866-01-05 | CA006150689 | TMAX       |       -15.6 |     3.92 |       1 | CA             |


Table #2
Filename: source_1.csv
Sample Rows in Markdown:
| datetime   | station     | obs_type   |   obs_value |   TMAX_F |   month | country_code   |
|:-----------|:------------|:-----------|------------:|---------:|--------:|:---------------|
| 1865-02-11 | SZ000006717 | TMAX       |       -22.2 |    -7.96 |       2 | SZ             |
| 1865-02-10 | SZ000006717 | TMAX       |       -18.8 |    -1.84 |       2 | SZ             |
| 1865-07-28 | USC00288878 | TMAX       |       -17.8 |    -0.04 |       7 | USC            |
| 1865-03-29 | SZ000006717 | TMAX       |       -17.6 |     0.32 |       3 | SZ             |
| 1865-02-21 | SZ000006717 | TMAX       |       -17.3 |     0.86 |       2 | SZ             |
| 1865-03-30 | SZ000006717 | TMAX       |       -15.4 |     4.28 |       3 | SZ             |
| 1865-03-23 | SZ000006717 | TMAX       |       -15.1 |     4.82 |       3 | SZ             |
| 1865-03-24 | SZ000006717 | TMAX       |       -15.1 |     4.82 |       3 | SZ             |
| 1865-02-20 | SZ000006717 | TMAX       |       -14.5 |     5.9  |       2 | SZ             |
| 1865-03-28 | SZ000006717 | TMAX       |       -14.3 |     6.26 |       3 | SZ             |


Table #3
Filename: source_2.csv
Sample Rows in Markdown:
| datetime   | station     | obs_type   |   obs_value |   TMAX_F |   month | country_code   |
|:-----------|:------------|:-----------|------------:|---------:|--------:|:---------------|
| 1867-07-08 | ASN00090015 | TMAX       |          15 |       59 |       7 | ASN            |
| 1867-09-14 | CA006122845 | TMAX       |          15 |       59 |       9 | CA             |
| 1867-09-29 | UK000047811 | TMAX       |          15 |       59 |       9 | UK             |
| 1867-04-02 | UK000047811 | TMAX       |          15 |       59 |       4 | UK             |
| 1867-07-08 | GM000004204 | TMAX       |          15 |       59 |       7 | GM             |
| 1867-10-24 | ITE00100554 | TMAX       |          15 |       59 |      10 | ITE            |
| 1867-09-28 | EIE00101859 | TMAX       |          15 |       59 |       9 | EIE            |
| 1867-10-01 | CA006150689 | TMAX       |          15 |       59 |      10 | CA             |
| 1867-10-28 | CA006137735 | TMAX       |          15 |       59 |      10 | CA             |
| 1867-09-28 | GM000004204 | TMAX       |          15 |       59 |       9 | GM             |


Table #4
Filename: source_3.csv
Sample Rows in Markdown:
| datetime   | station     | obs_type   |   obs_value |   TMAX_F |   month | country_code   |
|:-----------|:------------|:-----------|------------:|---------:|--------:|:---------------|
| 1864-02-26 | SZ000006717 | TMAX       |       -34   |   -29.2  |       2 | SZ             |
| 1864-02-08 | SZ000006717 | TMAX       |       -17.4 |     0.68 |       2 | SZ             |
| 1864-02-17 | CA006158350 | TMAX       |       -16.7 |     1.94 |       2 | CA             |
| 1864-01-03 | SZ000006717 | TMAX       |       -16.5 |     2.3  |       1 | SZ             |
| 1864-01-02 | CA006158350 | TMAX       |       -16.1 |     3.02 |       1 | CA             |
| 1864-02-10 | SZ000006717 | TMAX       |       -15.9 |     3.38 |       2 | SZ             |
| 1864-01-14 | EZE00100082 | TMAX       |       -15.1 |     4.82 |       1 | EZE            |
| 1864-02-09 | SZ000006717 | TMAX       |       -15   |     5    |       2 | SZ             |
| 1864-02-19 | SZ000006717 | TMAX       |       -14.7 |     5.54 |       2 | SZ             |
| 1864-02-05 | SZ000006717 | TMAX       |       -14.4 |     6.08 |       2 | SZ             |


Target Schema:
|   month |   station |   datetime |   obs_type |   obs_value |   TMAX_F |   country_code |
|--------:|----------:|-----------:|-----------:|------------:|---------:|---------------:|
|       1 |      2275 |       2275 |       2275 |        2275 |     2275 |           2275 |
|       2 |      2111 |       2111 |       2111 |        2111 |     2111 |           2111 |
|       3 |      2336 |       2336 |       2336 |        2336 |     2336 |           2336 |
|       4 |      2118 |       2118 |       2118 |        2118 |     2118 |           2118 |
|       5 |      2069 |       2069 |       2069 |        2069 |     2069 |           2069 |
|       6 |      1791 |       1791 |       1791 |        1791 |     1791 |           1791 |
|       7 |      1834 |       1834 |       1834 |        1834 |     1834 |           1834 |
|       8 |      1822 |       1822 |       1822 |        1822 |     1822 |           1822 |
|       9 |      1808 |       1808 |       1808 |        1808 |     1808 |           1808 |
|      10 |      2220 |       2220 |       2220 |        2220 |     2220 |           2220 |

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
source_2.csv
source_3.csv
test: test_0.csv
test_1.csv
test_2.csv
test_3.csv