I have a dataframe semble this:
id city 2018 2019
0 1 bj 2.0 3.0
1 2 sh 3.0 3.5
2 3 gz 2.5 4.0
I need to vertically flatten column 2018
and 2019
to year
and price
, and then merge based on id
and city
.
The output I want is like this:
id city year price
0 1 bj 2018 2.0
1 1 bj 2019 3.0
2 2 sh 2018 3.0
3 2 sh 2019 3.5
4 3 gz 2018 2.5
5 3 gz 2019 4.0
How can I do that? Thanks.