Dear All,
I have an excel file where data is stored in the following format (Data can be 0,1 or blank):
Date SecurityA Security B … Security ZZ
201101 0 1 … 0
201102 1 1 … 0
…
…
202012 0 0 … 1
Now I want to get all column data stacked under each other. So the desired format is (just two columns):
Date Security
201101 0
201102 1
.
.
202012 0
201101 1
201102 1
…
…
202012 0
201101 1
201102 1
Can anyone please suggest me a python code which might help me do that. I am trying the following but it just does not work:
import pandas as pd
data = pd.read_csv('data.csv')
data_long = pd.melt(data, id_vars=['Date'], var_name='Security', value_name='Value')
panel_data = data_long.pivot_table(values='Value', index='Date', columns='Security')