Is there a pythonic way to do a contingency table in Pandas?

后端 未结 4 617
傲寒
傲寒 2020-12-30 00:09

Given a dataframe that looks like this:

            A   B      
2005-09-06  5  -2  
2005-09-07 -1   3  
2005-09-08  4   5 
2005-09-09 -8   2
2005-09-10 -2  -         


        
4条回答
  •  失恋的感觉
    2020-12-30 00:40

    Here's a really useful page about the pandas crosstab function:

    http://chrisalbon.com/python/pandas_crosstabs.html

    So I think for what you'd like to do you should use

    import pandas as pd
    pd.crosstab(data['A']>0, data['B']>0)
    

    Hope that helps!

提交回复
热议问题