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


Posted in Python onMay 12, 2021

一、确定核算规则

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

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

# -*- 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"))

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

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

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

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

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

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

Python 相关文章推荐
python client使用http post 到server端的代码
Feb 10 Python
使用Python中PDB模块中的命令来调试Python代码的教程
Mar 30 Python
Tensorflow 查看变量的值方法
Jun 14 Python
python实现将汉字保存成文本的方法
Nov 16 Python
解决python写入带有中文的字符到文件错误的问题
Jan 31 Python
Python自定义一个异常类的方法
Jun 27 Python
python实现的自动发送消息功能详解
Aug 15 Python
解决pandas展示数据输出时列名不能对齐的问题
Nov 18 Python
django自定义非主键自增字段类型详解(auto increment field)
Mar 30 Python
python中什么是面向对象
Jun 11 Python
详解python网络进程
Jun 15 Python
python区块链持久化和命令行接口实现简版
May 25 Python
用python开发一款操作MySQL的小工具
May 12 #Python
浅谈Python类的单继承相关知识
May 12 #Python
PyCharm 安装与使用配置教程(windows,mac通用)
在python中实现导入一个需要传参的模块
May 12 #Python
python 使用Tensorflow训练BP神经网络实现鸢尾花分类
PyTorch 如何设置随机数种子使结果可复现
May 12 #Python
Python Parser的用法
May 12 #Python
You might like
php 字符转义 注意事项
2009/05/27 PHP
解析PHP计算页面执行时间的实现代码
2013/06/18 PHP
PHP+redis实现添加处理投票的方法
2015/11/14 PHP
使用PHP实现生成HTML静态页面
2015/11/18 PHP
再谈Yii Framework框架中的事件event原理与应用
2020/04/07 PHP
php实现图片压缩处理
2020/09/09 PHP
IE php关于强制下载文件的代码
2008/08/23 Javascript
offsetParent 算法分析
2010/04/05 Javascript
jQueryUI写一个调整分类的拖放效果实现代码
2012/05/10 Javascript
jQuery中index()的用法分析
2014/09/05 Javascript
EasyUI加载完Html内容样式渲染完成后显示
2016/07/25 Javascript
jquery判断页面网址是否有效的两种方法
2016/12/11 Javascript
利用Angular.js编写公共提示模块的方法教程
2017/05/28 Javascript
Vue项目中使用Vux的安装过程
2018/05/01 Javascript
Bootstrap实现模态框效果
2019/09/30 Javascript
javascript实现拖拽碰撞检测
2020/03/12 Javascript
学习python (1)
2006/10/31 Python
Python部署web开发程序的几种方法
2017/05/05 Python
基于Python对象引用、可变性和垃圾回收详解
2017/08/21 Python
Python实现两款计算器功能示例
2017/12/19 Python
python 3.6.4 安装配置方法图文教程
2018/09/18 Python
Python编程图形库之Pillow使用方法讲解
2018/12/28 Python
python opencv对图像进行旋转且不裁剪图片的实现方法
2019/07/09 Python
在PyCharm的 Terminal(终端)切换Python版本的方法
2019/08/02 Python
在flask中使用python-dotenv+flask-cli自定义命令(推荐)
2020/01/05 Python
基于Python的OCR实现示例
2020/04/03 Python
python super()函数的基本使用
2020/09/10 Python
html5清空画布方法(三种)
2017/10/16 HTML / CSS
兰蔻美国官网:Lancome美国
2017/04/25 全球购物
澳大利亚在线性感内衣商店:Fantasy Lingerie
2021/02/07 全球购物
2014领导班子正风肃纪思想汇报
2014/09/18 职场文书
个人作风建设剖析材料
2014/10/11 职场文书
公务员党的群众路线教育实践活动学习心得体会
2014/10/30 职场文书
婚宴邀请函
2015/01/30 职场文书
电信营业员岗位职责
2015/04/14 职场文书
vue生命周期钩子函数以及触发时机
2022/04/26 Vue.js