I have the following data set :
and I want to extract a new dataframe of the following form :
I tried this code but I got "NaN" for all cells
years = list(df_le["Year"].unique())
df2 =pd.DataFrame()
df2["Country"] =list(df_le["Country"].unique())
for year in years :
df2[year] = df_le[df_le["Year"]==year]["Life expectancy "]