Question: I have the following data structure

```
Date         Agric  Food 
01/01/1990    1.3   0.9  
01/02/1990    1.2   0.9 

```

I would like to covert it into the format

```
Date        Sector  Beta
01/01/1990  Agric   1.3
01/02/1990  Agric   1.2
01/01/1990  Food    0.9
01/02/1990  Food    0.9

```

while I am sure I can do this in a complicated way, is there a way of doing this in a few line of code?

Answer: 
Using [**`pd.DataFrame.melt`**](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.melt.html)

```
df.melt('Date', var_name='Sector', value_name='Beta')

         Date Sector  Beta
0  01/01/1990  Agric   1.3
1  01/02/1990  Agric   1.2
2  01/01/1990   Food   0.9
3  01/02/1990   Food   0.9

```
Use `set_index` and `stack`:

```
df.set_index('Date').rename_axis('Sector',axis=1).stack()\
  .reset_index(name='Beta')

```

Output:

```
         Date Sector  Beta
0  01/01/1990  Agric   1.3
1  01/01/1990   Food   0.9
2  01/02/1990  Agric   1.2
3  01/02/1990   Food   0.9

```