python 统计工作簿中每个人名出现的次数
工作簿
需求:统计人名出现的次数
代码:
# coding=gbk
import pandas as pd
import re
def extract_chinese(txt):
pattern = re.compile("[\u4e00-\u9fa5]")
return "".join(pattern.findall(txt))
names = {
}
data = pd.read_excel("./工作簿3.xlsx")
# 统计工作簿中每个 名字 出现的次数
for index, row in data.iterrows():
for i in row:
try:
i = extract_chinese(i)
if names.get(i) is None:
names[i] = 1
else:
names[i] += 1
except:
pass
print(names)
输出:
本文来自博客园,作者:CuriosityWang,转载请注明原文链接:https://www.cnblogs.com/curiositywang/p/14812658.html