# 教你使用Pandas直接核算Excel中的快递费用

## 二、根据核算规则编写代码，生成核算列

```# -*- coding:utf-8 -*-
import pandas as pd
from math import ceil
import os

if weight <= 3:
totel = 2.5
elif  (weight >= 3) and (weight<=5):
totel = 3.5 + ceil((weight-3))*1
else:
totel = ceil(weight)*1

if weight <= 3:
totel = 2.5
elif  (weight >= 3) and (weight<=5):
totel = 3.5 + ceil((weight-3))*1
else:
totel = ceil(weight)*2

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

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
if  weight <= 1:
totel = 9
else:
totel = 9 + ceil(weight编程客栈-1)*6
if  weight <= 1:
totel = 15
else:
totel = 15 + ceil(weight-1)*12
if  weight <= 1:
totel = 16
else:
totel = 15 + ceil(weight-1)*18
else:
print("你输入的省份不合法！！！")

file_path = input("请输入文件路径：")
sheet_name = input("请输入工作簿名称：")
#获取省份一列
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["最新核算结果"] = 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+"最新核算结果"+".xlsx"))
```