def clearFile(): with open(gp.getPath('city'), "w", encoding="UTF-8") as f: f.write("") with open(gp.getPath('facility'), "w", encoding="UTF-8") as f: f.write("") with open(gp.getPath('procejure'), "w", encoding="UTF-8") as f: f.write("")
def adjustSize(): finalDict = {} global oriCsv oriCsv = getExistsPos() finalCsv = getFinalCsv() dis = len(oriCsv) - len(finalCsv) #两个csv相差的行数 if dis != 0: #如果第一列银行数总数没变,那就调整完毕 if len(finalCsv.keys()) == 0: #如果本身文件就是空 newList = oriCsv[gp.firstColEng].tolist() finalDict[gp.firstColEng] = newList finalCsv = pd.DataFrame(finalDict) finalCsv.to_csv(gp.getPath('finalCsv'), index=False) #空值用NAN代表 else: for listName in finalCsv.keys(): if len(finalCsv[listName]) != 0: if listName != gp.firstColEng: #如果这列不是银行才补充None newList = finalCsv[listName].tolist() newList.extend([None] * dis) #相同行数的某个list else: #如果是银行 newList = oriCsv[gp.firstColEng].tolist() else: newList = [None] * dis finalDict[listName] = newList #转换dataframe finalCsv = pd.DataFrame(finalDict) finalCsv.to_csv(gp.getPath('finalCsv'), index=False, na_rep='NaN') #空值用NAN代表
def getFinalCsv(): finalCsv = [] csvPath = gp.getPath('finalCsv') if os.path.isfile(csvPath): #如果不存在就返回False f = open(gp.getPath('finalCsv')) #解决pandas读取中文名的文件名问题 try: finalCsv = pd.read_csv(f, encoding='utf-8') #解决编码问题utf-8 except: #如果为空的话 return pd.DataFrame({}) else: finalCsv = pd.DataFrame({}) with open(csvPath, "w", encoding="UTF-8") as f: pass finalCsv.to_csv(csvPath, index=False) return finalCsv
def getProcedure(): List = [] Range = [] lastPos = [] with open(gp.getPath('procejure'), "r", encoding="UTF-8") as f: for line in f.readlines(): List = line.split('|') Range = List[0].split(',') lastPos = List[1].split(',') return Range, lastPos
def getProcedure(): List = [] strRange = [] strlastPos = [] floatRange = [] floatlastPos = [] List = getProcejureDetail(gp.getPath('procejure')) if len(List) == 0: #如果是空,直接返回 return floatRange, floatlastPos strRange = List[0].split(',') strlastPos = List[1].split(',') for each in strRange: floatRange.append(gp.str2float(each)) for each in strlastPos: floatlastPos.append(gp.str2float(each)) return floatRange, floatlastPos
def saveInCsv(finalCsv, each, point): finalDataFrame = pd.DataFrame(finalCsv) finalDataFrame.to_csv(gp.getPath('finalCsv'), index=False) print('当前' + each + '搜索到了' + str(point) + '条数据')
def saveInFile(s, path): with open(gp.getPath(path), 'w') as f: f.write(s)