计算所有数据框中每一列的正值

时间:2020-05-05 17:11:05

标签: python-3.x pandas dataframe

是否可以计算数据帧中每一列的正值?

我试图用'count'来做

template <typename Data>
bool BinaryTreeVec<Data>::NodeVec::HasLeftChild() const noexcept{
    if( 2 * index + 1 < treeVec.Size())
        return ( treeVec[2 * index + 1].flag == true );

    return false; 
}

“>”(大于)似乎不起作用。

我尝试使用'value_counts',它在此示例中适用于列'A'

import pandas as pd
import numpy as np

np.random.seed(18)

df = pd.DataFrame(np.random.randint(-10,10,size=(5, 4)), columns=list('ABCD'))

print(df)
   A  B  C  D
0  0  9 -5  7
1  4  8 -8 -2
2 -8  7 -5  5
3  0  0  1 -6
4 -6  1 -9 -7


positive_count = df.gt(0).count()

print(positive_count)
A    5
B    5
C    5
D    5
dtype: int64

但是我想一次获得所有列的结果。

有人有帮助我的想法吗?

0 个答案:

没有答案