python-collection count函数

count函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import pandas as pd
import numpy as np

from collections import Counter

file=r"明细.xlsx"
sheet_name_spxm = '1228'
sheet_name_mas = '1227'

data_spxm = pd.read_excel(file, sheet_name=sheet_name_spxm)
data_spxm = np.array(data_spxm.iloc[:,0])
train_data_spxm = data_spxm.tolist()

data_mas = pd.read_excel(file, sheet_name=sheet_name_mas)
data_mas = np.array(data_mas.iloc[:,1])
train_data_mas = data_mas.tolist()

data_spxm_dict = Counter()
data_mas_dict = Counter()

for spxm in train_data_spxm:
data_spxm_dict[spxm] += 1

for mas in train_data_mas:
data_mas_dict[mas] += 1

result = data_spxm_dict - data_mas_dict
print(result)
print(len(result))