教你使用Pandas直接核算Excel中的快遞費(fèi)用
一、確定核算規(guī)則
二、根據(jù)核算規(guī)則編寫代碼,生成核算列
# -*- coding:utf-8 -*- import pandas as pd from math import ceil import os def account(adress,weight): if adress == "湖南": if weight <= 3: totel = 2.5 elif (weight >= 3) and (weight<=5): totel = 3.5 + ceil((weight-3))*1 else: totel = ceil(weight)*1 return totel elif adress in ["河北","天津","山西","浙江","江蘇","安徽","福建","山東","江西","廣東","廣西","河南","湖北","陜西","四川","重慶","云南","貴州"]: if weight <= 3: totel = 2.5 elif (weight >= 3) and (weight<=5): totel = 3.5 + ceil((weight-3))*1 else: totel = ceil(weight)*2 return totel elif adress in ["深圳","北京","上海"]: if weight <= 3: totel = 3.3 elif (weight >= 3) and (weight<=5): totel = 3.5 + ceil((weight-3))*1.5 else: totel = ceil(weight)*2 return totel elif adress in ["海南","遼寧","黑龍江","吉林"]: if weight <= 3: totel = 2.5 elif (weight >= 3) and (weight<=5): totel = 3.5 + ceil((weight-3))*2.5 else: totel = ceil(weight)*3 return totel elif adress in ["內(nèi)蒙古","甘肅","寧夏","青海"]: if weight <= 1: totel = 9 else: totel = 9 + ceil(weight-1)*6 return totel elif adress == "新疆": if weight <= 1: totel = 15 else: totel = 15 + ceil(weight-1)*12 return totel elif adress == "西藏": if weight <= 1: totel = 16 else: totel = 15 + ceil(weight-1)*18 return totel else: print("你輸入的省份不合法?。。?) file_path = input("請(qǐng)輸入文件路徑:") sheet_name = input("請(qǐng)輸入工作簿名稱:") 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["最新核算結(jié)果"] = totel file_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+"最新核算結(jié)果"+".xlsx"))
三、輸入賬單,進(jìn)行核算。
在腳本文件目錄中執(zhí)行pyinstaller -F hesuan.py 進(jìn)行打包exe文件,如果為安裝pyinstaller,使用pip install pyinstaller 安裝。點(diǎn)擊運(yùn)行打包后的exe文件,輸入文件的路徑名和sheet名,就可以進(jìn)行自動(dòng)核算,腳本運(yùn)行完成后會(huì)自動(dòng)保存一個(gè)新的Excel文件。
到此這篇關(guān)于教你使用Pandas直接核算Excel中快遞費(fèi)用的文章就介紹到這了,更多相關(guān)Pandas核算Excel中快遞費(fèi)用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- pandas中DataFrame檢測(cè)重復(fù)值的實(shí)現(xiàn)
- pandas DataFrame.shift()函數(shù)的具體使用
- pandas取dataframe特定行列的實(shí)現(xiàn)方法
- 利用python Pandas實(shí)現(xiàn)批量拆分Excel與合并Excel
- Pandas DataFrame轉(zhuǎn)換為字典的方法
- 解決python3安裝pandas出錯(cuò)的問題
- Pandas爆炸函數(shù)的使用技巧
- Pandas||過濾缺失數(shù)據(jù)||pd.dropna()函數(shù)的用法說明
- 使用pandas或numpy處理數(shù)據(jù)中的空值(np.isnan()/pd.isnull())
- 教你漂亮打印Pandas DataFrames和Series
相關(guān)文章
Pytest實(shí)現(xiàn)setup和teardown的詳細(xì)使用詳解
這篇文章主要介紹了Pytest實(shí)現(xiàn)setup和teardown的詳細(xì)使用詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04python網(wǎng)絡(luò)編程學(xué)習(xí)筆記(10):webpy框架
webpy小巧,簡(jiǎn)單,實(shí)用,可以快速的完成簡(jiǎn)單的web頁(yè)面。這里根據(jù)webpy Cookbook簡(jiǎn)要的介紹一下webpy框架,需要的朋友可以參考下2014-06-06python實(shí)現(xiàn)動(dòng)態(tài)創(chuàng)建類的方法分析
這篇文章主要介紹了python實(shí)現(xiàn)動(dòng)態(tài)創(chuàng)建類的方法,結(jié)合實(shí)例形式分析了Python動(dòng)態(tài)創(chuàng)建類的原理、實(shí)現(xiàn)方法及相關(guān)操作技巧,需要的朋友可以參考下2019-06-06keras.layers.Conv2D()函數(shù)參數(shù)用法及說明
這篇文章主要介紹了keras.layers.Conv2D()函數(shù)參數(shù)用法及說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02Pytorch從0實(shí)現(xiàn)Transformer的實(shí)踐
本文主要介紹了Pytorch從0實(shí)現(xiàn)Transformer的實(shí)踐,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05PyCharm 解決找不到新打開項(xiàng)目的窗口問題
這篇文章主要介紹了PyCharm 解決找不到新打開項(xiàng)目的窗口問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-01-01