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   |
|:-----------|:------------|:-----------|------------:|---------:|--------:|:---------------|
| 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 #2
Filename: source_1.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.01 |       1 | CA             |
| 1866-01-14 | CA006158350 | TMAX       |       -16.1 |     3.01 |       1 | CA             |
| 1866-01-15 | CA006150689 | TMAX       |       -16.1 |     3.01 |       1 | CA             |
| 1866-01-08 | CA006150689 | TMAX       |       -16.1 |     3.01 |       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 #3
Filename: source_2.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.03 |       7 | USC            |
| 1865-03-29 | SZ000006717 | TMAX       |       -17.6 |     0.31 |       3 | SZ             |
| 1865-02-21 | SZ000006717 | TMAX       |       -17.3 |     0.85 |       2 | SZ             |
| 1865-03-30 | SZ000006717 | TMAX       |       -15.4 |     4.27 |       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.89 |       2 | SZ             |
| 1865-03-28 | SZ000006717 | TMAX       |       -14.3 |     6.25 |       3 | SZ             |


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.39 |     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.01 |       1 | CA             |
| 1864-02-10 | SZ000006717 | TMAX       |      -15.9  |     3.37 |       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.53 |       2 | SZ             |
| 1864-02-05 | SZ000006717 | TMAX       |      -14.4  |     6.07 |       2 | SZ             |


Target Schema:
| station     |   datetime |   obs_type |   obs_value |   TMAX_F |   month |   country_code |
|:------------|-----------:|-----------:|------------:|---------:|--------:|---------------:|
| AGE00135039 |        935 |        935 |         935 |      935 |     935 |            935 |
| ASN00066062 |       1110 |       1110 |        1110 |     1110 |    1110 |           1110 |
| ASN00074128 |         85 |         85 |          85 |       85 |      85 |             85 |
| ASN00086071 |       1153 |       1153 |        1153 |     1153 |    1153 |           1153 |
| ASN00090015 |        971 |        971 |         971 |      971 |     971 |            971 |
| AU000005901 |       1300 |       1300 |        1300 |     1300 |    1300 |           1300 |
| BE000006447 |       1301 |       1301 |        1301 |     1301 |    1301 |           1301 |
| CA006101872 |        169 |        169 |         169 |      169 |     169 |            169 |
| CA006106362 |        465 |        465 |         465 |      465 |     465 |            465 |
| CA006110549 |        540 |        540 |         540 |      540 |     540 |            540 |

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