教你使用Pandas直接核算Excel中的快遞費用
一、確定核算規(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("請輸入文件路徑:")
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["最新核算結(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"))
三、輸入賬單,進行核算。

在腳本文件目錄中執(zhí)行pyinstaller -F hesuan.py 進行打包exe文件,如果為安裝pyinstaller,使用pip install pyinstaller 安裝。點擊運行打包后的exe文件,輸入文件的路徑名和sheet名,就可以進行自動核算,腳本運行完成后會自動保存一個新的Excel文件。



到此這篇關(guān)于教你使用Pandas直接核算Excel中快遞費用的文章就介紹到這了,更多相關(guān)Pandas核算Excel中快遞費用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- pandas中DataFrame檢測重復值的實現(xiàn)
- pandas DataFrame.shift()函數(shù)的具體使用
- pandas取dataframe特定行列的實現(xiàn)方法
- 利用python Pandas實現(xiàn)批量拆分Excel與合并Excel
- Pandas DataFrame轉(zhuǎn)換為字典的方法
- 解決python3安裝pandas出錯的問題
- Pandas爆炸函數(shù)的使用技巧
- Pandas||過濾缺失數(shù)據(jù)||pd.dropna()函數(shù)的用法說明
- 使用pandas或numpy處理數(shù)據(jù)中的空值(np.isnan()/pd.isnull())
- 教你漂亮打印Pandas DataFrames和Series
相關(guān)文章
Pytest實現(xiàn)setup和teardown的詳細使用詳解
這篇文章主要介紹了Pytest實現(xiàn)setup和teardown的詳細使用詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-04-04
python網(wǎng)絡(luò)編程學習筆記(10):webpy框架
webpy小巧,簡單,實用,可以快速的完成簡單的web頁面。這里根據(jù)webpy Cookbook簡要的介紹一下webpy框架,需要的朋友可以參考下2014-06-06
python實現(xiàn)動態(tài)創(chuàng)建類的方法分析
這篇文章主要介紹了python實現(xiàn)動態(tài)創(chuàng)建類的方法,結(jié)合實例形式分析了Python動態(tài)創(chuàng)建類的原理、實現(xiàn)方法及相關(guān)操作技巧,需要的朋友可以參考下2019-06-06
keras.layers.Conv2D()函數(shù)參數(shù)用法及說明
這篇文章主要介紹了keras.layers.Conv2D()函數(shù)參數(shù)用法及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-02-02
Pytorch從0實現(xiàn)Transformer的實踐
本文主要介紹了Pytorch從0實現(xiàn)Transformer的實踐,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-05-05

