I have daily stock data inside a list of n dataframes (each stock has its own dataframe). I want to select m rows on equal time intervals from each dataframe and append them to dataframes inside another list. Basically the new list should have m dataframes - which is the number the number of days, and each dataframe length n - the number of stocks. I tried with nested for loops but it just didn't work
cross_section = []
cross_sections_list = []
for m in range(0, len(datalist[0]), 100):
for n in range(len(datalist)):
cross_section.append(datalist[n].iloc[m])
cross_sections_list.append(cross_section)
this code didnt do anything. my machine just stacked on it. if there is another way like multiindexing for example I would love trying it too.
For example
input:
[
Adj Close Ticker
Date
2020-06-01 321.850006 AAPL
2020-06-02 323.339996 AAPL
2020-06-03 325.119995 AAPL
2020-06-04 322.320007 AAPL
2020-06-05 331.500000 AAPL
2020-06-08 333.459991 AAPL
2020-06-09 343.989990 AAPL
2020-06-10 352.839996 AAPL ,
Adj Close Ticker
Date
2020-06-01 182.830002 MSFT
2020-06-02 184.910004 MSFT
2020-06-03 185.360001 MSFT
2020-06-04 182.919998 MSFT
2020-06-05 187.199997 MSFT
2020-06-08 188.360001 MSFT
2020-06-09 189.800003 MSFT
2020-06-10 196.839996 MSFT ]
output:
[
Adj Close Ticker
Date
2020-06-01 321.850006 AAPL
2020-06-01 182.830002 MSFT ,
Adj Close Ticker
Date
2020-06-03 325.119995 AAPL
2020-06-03 185.360001 MSFT ,
Adj Close Ticker
Date
2020-06-05 331.500000 AAPL
2020-06-05 187.199997 MSFT ]
and so on.
Thank you