I have a dataframe of the following format:
> example_df
P_ID Income2000 Income2001 Income2002
1 1 21 22 23
2 2 15 15 15
3 3 10 13 15
where I have multiple persons with Income over three years given by the colums Income2000, Income2001 and Income2002.
Now I was wondering whether there is a fast and effective way of transforming the above dataframe into a dataframe that looks like:
> example_df2
Year P_ID Income
1 2000 1 21
2 2001 1 22
3 2002 1 23
4 2000 2 15
5 2001 2 15
6 2002 2 15
7 2000 3 10
8 2001 3 13
9 2002 3 15