Search code examples
pythonpython-3.xpandasdataframemulti-index

Counting in Multiindex DataFrame In pandas


I have the following df2:

df2
Out[94]: 
Symbols     ADANIPORTS.NS  ASIANPAINT.NS  ...  WIPRO.NS   ZEEL.NS
Date                                      ...                    
2015-06-15            NaN            NaN  ...       NaN       NaN
2015-06-16       0.010160       0.009162  ... -0.001109  0.016949
2015-06-17      -0.007024       0.008086  ...  0.011564  0.017681
2015-06-18       0.000000       0.025751  ...  0.017477 -0.011678
2015-06-19      -0.020579       0.015159  ...  0.009797 -0.019885
                  ...            ...  ...       ...       ...
2020-06-04      -0.001031      -0.048236  ...  0.023184  0.050588
2020-06-05       0.005749       0.002938  ...  0.011561  0.002918
2020-06-08       0.006302      -0.002624  ...  0.035200 -0.044374
2020-06-09       0.008010       0.004773  ... -0.035769 -0.023598
2020-06-10       0.001445      -0.003715  ... -0.006183 -0.013513

[1226 rows x 50 columns]

How can i get the number of Symbols each day which were above .050 ?


Solution

  • You use df.gt with sum over axis 1.

    df2.gt(0.5).sum(1)