I'm trying to pivot my pandas dataset. Here's my sample:
sample = {'Country' : ["US","US","US","UK","UK","UK"],
"Indicator": ["Tax","Import","Export","Tax","Import","Export"],
"2019":[1,2,3,4,5,6],
"2020":[7,8,9,10,11,12],
"2021":[13,14,15,16,17,18]}
sample_df = pd.DataFrame(sample)
And I'm trying to get the data in the following structure:
target = {"Country": ["US","US","US","UK","UK","UK"],
"Date": ["2019","2020","2021","2019","2020","2021"],
"Tax": [1,7,13,4,10,16],
"Import": [2,8,14,5,11,17],
"Export": [3,9,15,6,12,18]}
target_df = pd.DataFrame(target)