厦门房地产网签备案的图片识别之二
作者:互联网
本文主要讲,在对图片的文本进行识别后,如何存入excel文件
先从二手房每天成交开始
主要使用openpyxl来对excel进行处理
import pandas as pd
from openpyxl import load_workbook
from datetime import date
def ershoufang(pngpath,datapath):
# 先获取当天的二手房成交数据
wb = load_workbook(pngpath)
zhuzhai_number = int(wb['data']['b3'].value)
others_number = int(wb['data']['b4'].value) - zhuzhai_number
zhuzhai_area = int(wb['data']['b5'].value)
others_area = int(wb['data']['b6'].value) - zhuzhai_area
wb.close()
# 把数据写入目标excel
# mode参数默认为w,如果是追加数据,必须为a,但函数内部处理时会自动把a替换为r+,因此直接用r+也可以
writer = pd.ExcelWriter(datapath,mode='r+')
book = load_workbook(datapath)
row = book['每天成交'].max_row
writer.book = book
writer.sheets = {ws.title: ws for ws in book.worksheets}
ershou_data = ([date.today(), '厦门', '二手','住宅', zhuzhai_number, zhuzhai_area], [date.today(), '厦门','二手','非住宅', others_number, others_area])
df = pd.DataFrame(ershou_data,columns= ['a','b','c','d','e','f'])
df.to_excel(writer, sheet_name='每天成交', startrow=row, encoding='utf-8', index=False, header=False)
writer.save()
ershoufang('C:\\data\\网签备份' + '\\' + str(date.today()) + '\\clfjy.xlsx','C:\\data\\网签备份\\database.xlsx')
标签:zhuzhai,wb,area,writer,number,之二,网签,data,备案 来源: https://blog.csdn.net/cwjcw81/article/details/113914230