比较两个Pandas 系列并打印差异
在此程序中,我们将比较两个熊猫系列,并打印该系列中的差异。通过差异,我们的意思是元素不匹配的索引位置。
算法
Step 1: Define two Pandas series, s1 and s2. Step 2: Compare the series using compare() function in the Pandas series. Step 3: Print their difference.
范例程式码
import pandas as pd
s1 = pd.Series([10,20,30,40,50,60])
s2 = pd.Series([10,30,30,40,55,60])
print("S1:\n", s1)
print("\nS2:\n", s2)
difference = s1.compare(s2)
print("\nDifference between the series: \n",difference)输出结果
S1:
0 10
1 20
2 30
3 40
4 50
5 60
dtype: int64
S2:
0 10
1 30
2 30
3 40
4 55
5 60
dtype: int64
Difference between the series:
self other
1 20.0 30.0
4 50.0 55.0解释
在上面的输出中,差异输出中有两列。一个是“self”,旁边是“other”。self指的是s1系列,而“other”指的是s2系列。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下