Suppose I have the following data:
>>> import numpy as np
>>> import pandas as pd
>>> data = np.random.randint(low=0, high=9, size=(10, 6))
>>> cols = ['wage1985', 'wage1986', 'hours1985', 'hours1986', 'race', 'edu']
>>> df = pd.DataFrame(data, columns=cols)
>>> df
wage1985 wage1986 hours1985 hours1986 race edu
0 8 2 5 0 3 1
1 7 1 5 8 4 1
2 7 5 3 7 3 7
3 8 3 8 3 1 0
4 2 7 1 6 7 2
5 8 1 3 8 1 6
6 4 7 6 6 1 7
7 0 6 6 2 6 8
8 8 7 4 2 0 7
9 2 2 7 2 3 6
Now I want to reshape it from wide to long, but there are some variables (edu, race) with values that should be repeated. The desired output would be something like the following (showing just the first observation).
>>> df_reshaped
year wage hours race edu
id
0 1985 8 5 3 1
1986 2 0 3 1
... . . . .
... . . . .