import pandas as pd
import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s: %(message)s')
res = pd.read_excel(r'slice.xlsx',encoding='gbk')
citys = pd.read_csv(r'xiaoqu.csv',encoding='gbk')
city = citys['普查村码']
name = res['普查村名']
code = res['普查小区码']
num = res['户数']
for m in city:
a = 0
b = 0
for k in zip(name,code,num):
if k[0] == m:
a += k[2]
b += 1
try:
if a > 1000 and b < 2:
info = {'普查村名': m, '普查小区码': k[1], '户数': a, '补码': '空码'}
logging.info(info)
df = pd.DataFrame([info])
df.to_csv('res.csv', mode='a+', encoding='utf8')
a = 0
b = 0
elif a > 1000 and a < 2000 and b >2:
info = {'普查村名':m,'普查小区码':k[1],'户数':a}
logging.info(info)
df = pd.DataFrame([info])
df.to_csv('res.csv',mode='a+',encoding='utf8')
a = 0
b = 0
# else:
# info = {'普查村名': m, '普查小区码': k[1], '户数': a,'补码':'补码'}
# logging.info(info)
# df = pd.DataFrame([info])
# df.to_csv('res.csv', mode='a+', encoding='utf8')
except:
pass
|