我有一个数据集如下:
>>>df = pd.DataFrame(
[
["site1", "2020-12-05T15:50:00", "0", "0"],
["site1", "2020-12-05T15:55:00", "0.5", "0"],
["site2", "2020-12-05T15:50:00", "0.5", "0"],
["site2", "2020-12-05T15:55:00", "1", "0"],
],
columns=["code", "site_time", "r1", "r2"],
)
>>>df
code site_time r1 r2
0 site1 2020-12-05T15:50:00 0 0
1 site1 2020-12-05T15:55:00 0.5 0
2 site2 2020-12-05T15:50:00 0.5 0
3 site2 2020-12-05T15:55:00 1 0
然后我想将其转换到下表:
code site_time trace value
site1 2020-12-05T15:50:00 r1 0
site1 2020-12-05T15:50:00 r2 0
site1 2020-12-05T15:55:00 r1 0.5
site1 2020-12-05T15:55:00 r2 0
site2 2020-12-05T15:50:00 r1 0.5
site2 2020-12-05T15:50:00 r2 0
site2 2020-12-05T15:55:00 r1 1
site2 2020-12-05T15:55:00 r2 0
我能问问我是怎么做到的吗?