我有一个值为 1 和 2 的 DataFrame。
我想在 DataFrame 的末尾添加一行,计算每列中 1 的个数。应该是类似的
COUNTIF(A:A,1)
并拖动到 excel 中的所有列
我试过类似df.loc['lastrow']=df.count()[1]
,但结果不正确。
我该怎么做以及这个函数 (count()[1]
) 有什么作用?
最佳答案
你可以在sum
之后做append
df.append(df.eq(1).sum(),ignore_index=True )
关于python - 如何在 Pandas 中使用countif添加一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57350424/