geo cel格式读取_用于将公式导出为ex​​cel和其他格式的新python库

2023-11-22 17:10

本文主要是介绍geo cel格式读取_用于将公式导出为ex​​cel和其他格式的新python库,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

geo cel格式读取

One of the typical challenges when doing export of numerical computations is how to include the way how you achieve the results. Typically if results should be in Excel sheet at the end, you want to see the computation formula if you click on each cell. There is a native way using some Excel driver (like XlsxWriter) available in Python, but if you are dealing with a big Excel sheet, it becomes quite inconvenient. This article is about a new library called Portable Spreadsheet that can easily overcome these problems.

导出数值计算时的典型挑战之一是如何包括实现结果的方式。 通常,如果结果应在末尾的Excel工作表中,则单击每个单元格都希望看到计算公式。 使用Python中可用的某些Excel驱动程序(如XlsxWriter)有一种本机方式,但是如果您要处理一个很大的Excel工作表,它将变得非常不便。 本文是关于一个名为Portable Spreadsheet的新库,它可以轻松克服这些问题。

简单的问题 (Simple problem)

Say that you have an e-shop written in Python and want to export some simple Excel sheet that summarizes revenues per each category. There can be just two columns, one representing the category and another one representing revenues.

假设您有一个用Python编写的电子商店,并且要导出一些简单的Excel表格,其中汇总了每个类别的收入。 只能有两列,一列代表类别,另一列代表收入。

Image for post
Simple problem definition
简单的问题定义

In the end, you want to see some aggregation functions, like the sum of all revenues, the article with minimal revenue, and say the sum of food and drinks as a new category (called grocery). What is crucial, the spreadsheet should be editable, it means, each computation should be exported as a formula (as illustrated in the figure above).

最后,您希望看到一些汇总功能,例如所有收入的总和,收入最小的商品,并将食品和饮料的总和作为一个新类别(称为食品杂货)说出来。 至关重要的是,电子表格应该是可编辑的,这意味着每个计算都应作为公式导出(如上图所示)。

使用可用的Excel驱动程序的方法 (Approach using available Excel drivers)

You can tackle this issue directly using some driver for Excel available in Python. Let’s say you choose XlsxWriter as your driver. Then you have to define each cell value and for the computations the way how you compute it plus the actual value after the computation. The code you have to write would follow the logic:

您可以使用Python中提供的一些Excel驱动程序直接解决此问题。 假设您选择XlsxWriter作为驱动程序。 然后,您必须定义每个像元值,并为计算定义计算方式以及计算后的实际值。 您必须编写的代码将遵循以下逻辑:

import xlsxwriter
workbook = xlsxwriter.Workbook('revenues.xlsx')
worksheet = workbook.add_worksheet()
food_rev = 1000
drinks_rev = 100
headphones_rev = 300
# Write categories
worksheet.write(0, 0, "Food")
worksheet.write(1, 0, "Drinks")
worksheet.write(2, 0, "Headphones")
# Write revenues
worksheet.write(0, 1, food_rev)
worksheet.write(1, 1, drinks_rev)
worksheet.write(2, 1, headphones_rev)
# Write results
worksheet.write_formula(3, 1, "=SUM(B1:B3)",
value=(food_rev + drinks_rev + headphones_rev))
worksheet.write_formula(4, 1, "=MIN(B1:B3)",
value=min(food_rev, drinks_rev, headphones_rev))
worksheet.write_formula(5, 1, "=B1+B2",
value=food_rev + drinks_rev)
# Close the sheet (in order to write it to the file)
workbook.close()

As you can see the code is not simple (nor complete) and you already had to hardwire the positions of each cell in it. You also had to use values for computations multiple times as you cannot directly use the values in the cell.

如您所见,代码并不简单(也不完整),并且您已经不得不硬编码其中每个单元的位置。 您还必须多次使用值进行计算,因为您无法直接使用单元格中的值。

What more is that when you decide to export to the different format (say JSON), you have to write this code again.

而且,当您决定导出为其他格式(例如JSON)时,必须再次编写此代码。

便携式电子表格方法 (Portable Spreadsheet approach)

Another way how to deal with all these issues elegantly is to use a library called Portable Spreadsheet (installable easily via pip install portable-spreadsheet). Consider the following code as the opposite of the previous one:

优雅地处理所有这些问题的另一种方法是使用一个名为Portable Spreadsheet的库(可通过pip install Portable-spreadsheet轻松安装)。 考虑以下代码与上一个相反:

import portable_spreadsheet as ps
# Create the spreadsheet with the correct labels
sheet = ps.Spreadsheet.create_new_sheet(
6, 1,
rows_labels=['Food', 'Drink', 'Headphones', 'Total', 'Minimal', 'Grocery'],
columns_labels=['Revenue']
)
# Set the values
sheet.loc['Food', 'Revenue'] = 15000
sheet.loc['Drink', 'Revenue'] = 16000
sheet.loc['Headphones', 'Revenue'] = 1000
# Set the computations
sheet.loc['Total', 'Revenue'] = sheet.loc['Food':'Total', 'Revenue'].sum()
sheet.loc['Minimal', 'Revenue'] = sheet.loc['Food':'Total', 'Revenue'].min()
sheet.loc['Grocery', 'Revenue'] = sheet.loc['Food', 'Revenue'] + \
sheet.loc['Drink', 'Revenue']
# Export result to Excel
sheet.to_excel("rev.xlsx")
# Export result to JSON
json = sheet.to_json()

As you can see, you completely removed redundancies in the code, it is shorter, easily readable, and what’s best, you can export not only to Excel but to every reasonable format (JSON, CSV, HTML, etc.). If you are familiar with Pandas DataFrame concept, you can see the straight motivation.

如您所见,您完全删除了代码中的冗余,它更短,更易于阅读,并且最好的是,您不仅可以导出到Excel,还可以导出为每种合理的格式(JSON,CSV,HTML等)。 如果您熟悉Pandas DataFrame概念,则可以看到直接的动机。

它是如何工作的? (How does it work under the hood?)

Internally, the principle of the Portable Spreadsheet library lies in the word constructing algorithm. Basically, each formula (in Excel, JSON, etc.) can be considered as a world in some language. This language is the Context-Free language defined by Context-Free grammar (see Chomsky hierarchy).

在内部,Portable Spreadsheet库的原理在于单词构造算法。 基本上,每个公式(在Excel,JSON等中)都可以被视为某种语言的世界。 此语言是无上下文语法定义的无上下文语言(请参阅Chomsky层次结构)。

This practically means that all that is needed is the definition of the prefixes and suffices for each operation. Operands here are the coordinates of the cells.

实际上,这意味着所需要做的就是定义每个操作的前缀和充分性。 这里的操作数是单元的坐标。

So, if you want to compute the sum of the items in the column, your operands are the coordinates of slice start and end, the operation is the sum (you have two inputs: operation and operands).

因此,如果要计算列中各项的总和,则您的操作数是切片起点和终点的坐标,操作是总和(您有两个输入:操作和操作数)。

Image for post
Prefixes and suffixes of operation and operands
操作和操作数的前缀和后缀

In the picture above, you can see prefixes and suffixes. Some prefixes and suffixes are empty sets. This picture is just an illustration, but it shows how each word can be constructed. All these prefixes and suffixes (and other rules) are defined as the grammars for each language in a separate file.

在上图中,您可以看到前缀和后缀。 一些前缀和后缀是空集。 这张图片只是一个插图,但是它显示了每个单词的构造方式。 所有这些前缀和后缀(以及其他规则)在单独的文件中定义为每种语言的语法。

The rest of the Portable Spreadsheet library is simple storing of words for each cell defined by its coordinates. Each word (like that one with the sum mentioned above) can be the part of the other word (acting as an operand). This approach allows defining grammars for each language that should be part of the export (like native language description, Python language, Excel).

便携式电子表格库的其余部分是简单存储每个由其坐标定义的单元格的单词。 每个单词(就像上面提到的总和一样)可以是另一个单词的一部分(充当操作数)。 这种方法允许为应该作为导出一部分的每种语言定义语法(例如本地语言描述,Python语言,Excel)。

摘要 (Summary)

The purpose of this article is to present a new library for Python called Portable Spreadsheet (pip install portable-spreadsheet) that allows you to easily export computation formulas in a spreadsheet to various type of formats (mainly Excel and JSON). So you can see how each computation in a spreadsheet is done without manually coding each cell.

本文的目的是为Python提供一个新的库,称为可移植电子表格(pip install Portable-spreadsheet),该库使您可以轻松地将电子表格中的计算公式导出为各种格式(主要是Excel和JSON)。 因此,您可以看到电子表格中的每个计算是如何完成的,而无需手动编码每个单元格。

翻译自: https://medium.com/@salacdav/new-python-library-for-exporting-formulas-to-excel-and-other-formats-dc78efe726ce

geo cel格式读取


http://www.taodudu.cc/news/show-8348324.html

相关文章:

  • Cannot get a text value from a numeric cell 解决方法
  • Cannot get a text value from a numeric cell异常处理
  • linux下分析cel文件,linux性能分析工具、调试工具浅析.ppt
  • ZOJ 3665 Yukari's Birthday(12年长春区域赛-K题-二分)
  • 【upc】2020年秋季组队训练赛第十五场 Black and White | 扫描线 + 线段树
  • 使用Sequelize连接数据库
  • matlab数组读取,Matlab读取csv字符串数组(Matlab read csv string array)
  • Android中两种播放器API对应的两种DRM
  • XMl 建模
  • 【合泰ht66fx0单片机学习】2_AD采集及外部中断
  • 【数学建模】【Python】自来水管道铺设问题(第一问)
  • 管道,more,grep,head/tail,cat使用
  • 数学建模——自来水管道铺设问题
  • Android值得付费的好游戏,Android用户愿意体验付费模式的游戏
  • 从玩家的角度看,内购,买断制,广告三种收费模式的区别对比
  • 【MySQL数据分析-统计游戏付费结构】
  • 调用高德逆地理接口_高德地图:地理/逆地理编码(示例代码)
  • 高中地理思维导图(浙江省学考专用)
  • 水文及地理数据
  • 浙江省计算机单考单招考试大纲2019,2019年浙江高职单招考试科目
  • 浙江开展空间地理大数据应用
  • 浙江高中地理历史计算机,浙江2014级高中生高考选科参考资料(24)—选科 化学地理技术 对应的985、211高校专业(类).pdf...
  • Android5.0及Material Design
  • Android 10: 新功能入门指南
  • 安卓6.0对系统隐私_如何在Android 5.0中固定屏幕以提高安全性和隐私性
  • android 开启屏幕固定,【玩机组】90%安卓用户都不知道的实用功能:屏幕固定
  • 基于Androidr 健身系统 计算机专业毕业设计源码90470
  • JDBC数据库编程
  • WebSphere技术专家沙龙活动演讲主题(2007年9月5日上海站)
  • 怎能叫我不开心呢!!
  • 这篇关于geo cel格式读取_用于将公式导出为ex​​cel和其他格式的新python库的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



    http://www.chinasem.cn/article/411643

    相关文章

    一文教你Python如何快速精准抓取网页数据

    《一文教你Python如何快速精准抓取网页数据》这篇文章主要为大家详细介绍了如何利用Python实现快速精准抓取网页数据,文中的示例代码简洁易懂,具有一定的借鉴价值,有需要的小伙伴可以了解下... 目录1. 准备工作2. 基础爬虫实现3. 高级功能扩展3.1 抓取文章详情3.2 保存数据到文件4. 完整示例

    使用Python实现IP地址和端口状态检测与监控

    《使用Python实现IP地址和端口状态检测与监控》在网络运维和服务器管理中,IP地址和端口的可用性监控是保障业务连续性的基础需求,本文将带你用Python从零打造一个高可用IP监控系统,感兴趣的小伙... 目录概述:为什么需要IP监控系统使用步骤说明1. 环境准备2. 系统部署3. 核心功能配置系统效果展

    基于Python打造一个智能单词管理神器

    《基于Python打造一个智能单词管理神器》这篇文章主要为大家详细介绍了如何使用Python打造一个智能单词管理神器,从查询到导出的一站式解决,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. 项目概述:为什么需要这个工具2. 环境搭建与快速入门2.1 环境要求2.2 首次运行配置3. 核心功能使用指

    Python实现微信自动锁定工具

    《Python实现微信自动锁定工具》在数字化办公时代,微信已成为职场沟通的重要工具,但临时离开时忘记锁屏可能导致敏感信息泄露,下面我们就来看看如何使用Python打造一个微信自动锁定工具吧... 目录引言:当微信隐私遇到自动化守护效果展示核心功能全景图技术亮点深度解析1. 无操作检测引擎2. 微信路径智能获

    Python中pywin32 常用窗口操作的实现

    《Python中pywin32常用窗口操作的实现》本文主要介绍了Python中pywin32常用窗口操作的实现,pywin32主要的作用是供Python开发者快速调用WindowsAPI的一个... 目录获取窗口句柄获取最前端窗口句柄获取指定坐标处的窗口根据窗口的完整标题匹配获取句柄根据窗口的类别匹配获取句

    利用Python打造一个Excel记账模板

    《利用Python打造一个Excel记账模板》这篇文章主要为大家详细介绍了如何使用Python打造一个超实用的Excel记账模板,可以帮助大家高效管理财务,迈向财富自由之路,感兴趣的小伙伴快跟随小编一... 目录设置预算百分比超支标红预警记账模板功能介绍基础记账预算管理可视化分析摸鱼时间理财法碎片时间利用财

    Python中的Walrus运算符分析示例详解

    《Python中的Walrus运算符分析示例详解》Python中的Walrus运算符(:=)是Python3.8引入的一个新特性,允许在表达式中同时赋值和返回值,它的核心作用是减少重复计算,提升代码简... 目录1. 在循环中避免重复计算2. 在条件判断中同时赋值变量3. 在列表推导式或字典推导式中简化逻辑

    python处理带有时区的日期和时间数据

    《python处理带有时区的日期和时间数据》这篇文章主要为大家详细介绍了如何在Python中使用pytz库处理时区信息,包括获取当前UTC时间,转换为特定时区等,有需要的小伙伴可以参考一下... 目录时区基本信息python datetime使用timezonepandas处理时区数据知识延展时区基本信息

    Python位移操作和位运算的实现示例

    《Python位移操作和位运算的实现示例》本文主要介绍了Python位移操作和位运算的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录1. 位移操作1.1 左移操作 (<<)1.2 右移操作 (>>)注意事项:2. 位运算2.1

    使用Python和Pyecharts创建交互式地图

    《使用Python和Pyecharts创建交互式地图》在数据可视化领域,创建交互式地图是一种强大的方式,可以使受众能够以引人入胜且信息丰富的方式探索地理数据,下面我们看看如何使用Python和Pyec... 目录简介Pyecharts 简介创建上海地图代码说明运行结果总结简介在数据可视化领域,创建交互式地