Skip to content
Advertisement

How to extract total year rows and columns from multiindex to create histograms in plotly

How do I create dataframes showing daily data for each year to create histograms in plotly?

                                Open        High        Low         Close       Volume      
   Date                         
   2019-06-26                  81.478964    81.789175   80.102395   80.422302   5731400  
   2019-06-27                  80.839148    81.411104   80.528937   81.129974   4111600 
   2019-06-28                  81.255994    81.682537   80.577409   81.527428   16436700
   .....
   2020-12-31                  81.255994    81.682537   80.577409   81.527428   16436700

I want my output for 2019 data frame to have all of 2019 transactions and my other dataframe to have all of 2020 transactions

Advertisement

Answer

Try with

d = {x : y for x , y in df.groupby(df.index.year)}
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement