I have financial performance Indicators for different companies, one row per year. Now I would like to have all the indicators per company over a specific range of years in one row.
Now my data looks similar to this:
import numpy as np
import pandas as pd
startyear = 2014
endyear = 2015
df = pd.DataFrame(np.array([
['AAPL', 2014, 0.2, 0.4, 1.5],
['AAPL', 2015, 0.3, 0.4, 2.0],
['AAPL', 2016, 0.2, 0.3, 1.5],
['GOGL', 2014, 0.4, 0.5, 0.5],
['GOGL', 2015, 0.6, 0.8, 1.0],
['GOGL', 2016, 0.3, 0.5, 2.0]]),
columns=['Name', 'Year', 'ROE', 'ROA', 'DE'])
newcolumns = (df.columns + [str(startyear)]).append(df.columns + [str(endyear)])
dfnew=pd.DataFrame(columns=newcolumns)
What I would like to have is (e.g. only years 2014 & 2015):
Name ROE2014 ROA2014 DE2014 ROE2015 ROA2015 DE2015
AAPL 0.2 0.4 1.5 0.3 0.4 2.0
GOOGL 0.4 0.5 0.5 0.6 0.8 1.0
So far I only managed to get the new column names, but somehow I can't get my head around how to fill this new DataFrame.