python办公自动化
需求:根据以下条件,输出供求关系级别的结果,红框右两列为条件
import pandas as pd
data = pd.read_excel('D:/xxx.xlsx') #数据源文件名,读取数据
level=[]
heat=[]
num=[]
for row in data.itertuples():
heat.append(getattr(row, '搜索热度'))
num.append(getattr(row, '搜索结果数'))
for t in range(len(heat)):
i=heat[t]
j=num[t]
if i>1000 and 5000<j<10000:
level.append('特级')
elif i>500 and j<=5000:
level.append('一级')
elif i>1000 and 10000<=j<=50000:
level.append('二级')
elif 500<i<=1000 and 5000<=j<=10000:
level.append('二级')
elif 200<i<=500 and j<1000:
level.append('二级')
elif i>1000 and j>50000:
level.append('五级')
elif 200<i<=500 and 1000<=j<3000:
level.append('三级')
elif i>100 and j<500:
level.append('四级')
elif 500<i<=1000 and j>10000:
level.append('六级')
else:
level.append('七级')
data['供求关系级别']=level
data.to_excel('D:/result.xlsx') #创建并将数据存入新的excel文件