python - 如何计算多系列中的真数?
问题描述
我有多个系列如下
import pandas as pd
ser1 = pd.Series([True, True, False, True, False], index=['John', 'Alice', 'Lisa', 'Flank', 'King'])
ser2 = pd.Series([True, False, False, False, True], index=['John', 'Alice', 'Lisa', 'Flank', 'King'])
ser3 = pd.Series([False, True, False, False, True], index=['John', 'Alice', 'Lisa', 'Flank', 'King'])
我想计算每一行的真数,例如约翰有两个真结果丽莎得到零。有人知道怎么做吗?
解决方案
让我们做pd.concat
pd.concat([ser1,ser2,ser3],axis=1).sum(axis=1)
John 2
Alice 2
Lisa 0
Flank 1
King 2
dtype: int64
推荐阅读
- sql - 使用 MERGE 语句时语法不正确
- python - FizzBuzz 还打印包含 3 和 5 的数字
- perl - 使用 DateTime 在 Perl 中显示 12 小时制时间
- r - 根据 Shiny R 中的单选按钮选择过滤列
- html - 如何传递图像下的文本,其中两列在引导程序上定义为图像,另一列用于文本?
- ios - 有人可以在发布图片时帮助我解决一个奇怪的 firebase 错误吗?
- chisel - makeSink 方法为外围设备制作 IO 的目的是什么
- python-3.x - 从文本条目返回值到其他类
- python - 为什么sk学习中的k-fold不打印数组值
- ros - GazeboRosControlPlugin 缺失