def get_area(area):
#统计各个城市的个数
area_dict = {}
for i in set(area):
area_dict[i] = area.count(i)
data = []
for item in area_dict:
data.append((item,area_dict[item]))
print(data)
def open_xlsx(file):
# 加载Excel数据,获得工作表和行数
data = xlrd.open_workbook(file) #读取工作表名称
table0 = data.sheet_by_name('51') #读取 当前sheet表
nrows = table0.nrows # 获取行数
return table0, nrows
def main():
table, nrows = open_xlsx('512.xlsx')
print('一共有{}行数据,开始清洗数据'.format(nrows))
area_list = []
for i in range(1, nrows):
job = table.row_values(i)[0]
company = table.row_values(i)[1]
companytype = table.row_values(i)[2]
area = table.row_values(i)[3][:2] # 地区取到城市,把区域去掉
if area:
area_list.append(area)
experience = table.row_values(i)[4]
degree = table.row_values(i)[5]
salary = table.row_values(i)[6]
get_area(area_list)