I have a data frame.
ID value-a value-b start-year end-year
1 10 15 2010 2012
2 20 24 2011 2013
3 10 20 2012 0
I wanna generate a new column 'year' such that: each row will be repeated for all the year from start year to end year.
ID value-a value-b year
1 10 15 2010
1 10 15 2011
1 10 15 2012
2 20 25 2011
2 20 24 2012
2 20 24 2013
3 10 20 2012
I have used the following code, but cant get correct output:
df =pd.concat([pd.DataFrame({'year': pd.date_range(row.start-year, row.end_year, freq='A'),
'value-a': row.value-a,
'value-b': row.value-b,columns=['year','value-a', 'value-b'])
for i, row in df.iterrows()], ignore_index=True)
Any help will be much appreciated.