教你使用Pandas直接核算Excel中的快遞費用
# -*- coding:utf-8 -*- import pandas as pd from math import ceilimport osdef account(adress,weight):if adress == '湖南':if weight <= 3: totel = 2.5elif (weight >= 3) and (weight<=5): totel = 3.5 + ceil((weight-3))*1else: totel = ceil(weight)*1return totelelif adress in ['河北','天津','山西','浙江','江蘇','安徽','福建','山東','江西','廣東','廣西','河南','湖北','陜西','四川','重慶','云南','貴州']:if weight <= 3: totel = 2.5elif (weight >= 3) and (weight<=5): totel = 3.5 + ceil((weight-3))*1else: totel = ceil(weight)*2 return totelelif adress in ['深圳','北京','上海']:if weight <= 3: totel = 3.3elif (weight >= 3) and (weight<=5): totel = 3.5 + ceil((weight-3))*1.5else: totel = ceil(weight)*2return totelelif adress in ['海南','遼寧','黑龍江','吉林']:if weight <= 3: totel = 2.5elif (weight >= 3) and (weight<=5): totel = 3.5 + ceil((weight-3))*2.5else: totel = ceil(weight)*3return totel elif adress in ['內蒙古','甘肅','寧夏','青海']:if weight <= 1: totel = 9else: totel = 9 + ceil(weight-1)*6 return totel elif adress == '新疆':if weight <= 1: totel = 15else: totel = 15 + ceil(weight-1)*12 return totel elif adress == '西藏':if weight <= 1: totel = 16else: totel = 15 + ceil(weight-1)*18 return totelelse:print('你輸入的省份不合法!!!') file_path = input('請輸入文件路徑:') sheet_name = input('請輸入工作簿名稱:')pf = pd.read_excel(file_path,sheet_name=sheet_name)#獲取省份一列pro = pf['省份'].values.tolist()#獲取重量一列wt = pf['重量'].values.tolist()#核算列totel = []for p,w in zip(pro,wt): print(p,w) totel.append(account(p,w))pf['最新核算結果'] = totelfile_name = os.path.basename(file_path)pf.to_excel(os.path.join(os.path.dirname(file_path),os.path.basename(file_path).split('.')[0]+sheet_name+'最新核算結果'+'.xlsx'))三、輸入賬單,進行核算。
在腳本文件目錄中執行pyinstaller -F hesuan.py 進行打包exe文件,如果為安裝pyinstaller,使用pip install pyinstaller 安裝。點擊運行打包后的exe文件,輸入文件的路徑名和sheet名,就可以進行自動核算,腳本運行完成后會自動保存一個新的Excel文件。
到此這篇關于教你使用Pandas直接核算Excel中快遞費用的文章就介紹到這了,更多相關Pandas核算Excel中快遞費用內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章:
