I'm stuck on how to stack/rearrange this dataframe to how I want it. Could someone help me out here? I've tried a bunch of different things with stacking but can't get it right.
I am trying to get it in order like this one, where each country has the info for all of the years, and then it goes to the next country.
Here is the code I have:
import pandas as pd
url = 'https://raw.githubusercontent.com/cleibowitz/Module-6/main/Module%206%20Dataset%20-%20co2%20PC%20transposed.csv'
data = pd.read_csv(url, index_col = 'Year')
data.columns.name = 'Country'
data = pd.DataFrame(data.stack().rename('value'))
data = data.reset_index()
data = data.set_index('Country')
data
I'd appreciate it if someone could explain how I can get the result I am looking for.