I have a big data frame with N columns. Columns are presented in pairs as follows:
- column 1: ISIN 1, sequence of daily dates (issuance to maturity of bond 1)
- column 2: historical data on prices wrt ISIN1
- column 3: ISIN 2, sequence of daily dates (issuance to maturity of bond 2)
- column 4: historical data on prices wrt ISIN2 and so on.
Columns are paired like this: the first two go together, and so the next two, until the end of the dataframe:
XS0552790049 Unnamed: 5583 XS0628646480 Unnamed: 5585
0 2010-10-22 100.0 2011-05-24 99.711
1 2010-10-25 100.0 2011-05-25 99.685
2 2010-10-26 100.0 2011-05-26 100.125
3 2010-10-27 100.0 2011-05-27 99.893
4 2010-10-28 100.0 2011-05-30 99.792
I want to subset this big data frame into N/2 subsamples, each containing a pair of columns "ISIN dates + prices", as shown above. I thought about using a for loop, but I am definitely missing something as it does not generate the subsamples. Perhaps I am indexing wrong.
Here's my attempt: I tried to create a dictionary containing a subsample for every key.
sub = {}
for i in range(0,len(df.columns)+1):
sub[i] = df.iloc[:,i:i+3]
I am pretty new with Python, so any suggestion is welcome.