主页 > 知识库 > 教你使用Pandas直接核算Excel中的快递费用

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

热门标签:Win7旗舰版 呼叫中心市场需求 电话运营中心 客户服务 百度AI接口 企业做大做强 语音系统 硅谷的囚徒呼叫中心

一、确定核算规则

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

# -*- 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 ["内蒙古","甘肃","宁夏","青海"]:
        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["最新核算结果"] = 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"))

三、输入账单,进行核算。

在脚本文件目录中执行pyinstaller -F hesuan.py 进行打包exe文件,如果为安装pyinstaller,使用pip install pyinstaller 安装。点击运行打包后的exe文件,输入文件的路径名和sheet名,就可以进行自动核算,脚本运行完成后会自动保存一个新的Excel文件。

到此这篇关于教你使用Pandas直接核算Excel中快递费用的文章就介绍到这了,更多相关Pandas核算Excel中快递费用内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
  • pandas中DataFrame检测重复值的实现
  • pandas DataFrame.shift()函数的具体使用
  • pandas取dataframe特定行列的实现方法
  • 利用python Pandas实现批量拆分Excel与合并Excel
  • Pandas DataFrame转换为字典的方法
  • 解决python3安装pandas出错的问题
  • Pandas爆炸函数的使用技巧
  • Pandas||过滤缺失数据||pd.dropna()函数的用法说明
  • 使用pandas或numpy处理数据中的空值(np.isnan()/pd.isnull())
  • 教你漂亮打印Pandas DataFrames和Series

标签:安康 海南 山西 喀什 长沙 济南 山西 崇左

巨人网络通讯声明:本文标题《教你使用Pandas直接核算Excel中的快递费用》,本文关键词  ;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 收缩
    • 微信客服
    • 微信二维码
    • 电话咨询

    • 400-1100-266