独立应用: 使用可重定位路径处理数据树
项目描述
独立 是一组用于使用 可重定位路径 处理 分层数据 的实用工具。
- 版本:
0.5.0
- 日期:
2020-05-14 23:59
- 文档:
- 来源:
- PyPI 仓库:
- 关键词:
计算、数据、依赖关系、工程、Excel、库、NumPy、Pandas、处理、Python、分辨率、科学、Simulink、树、实用程序
- 版权:
2015 欧洲委员会 (JRC-IET)
- 许可:
目前只有预期功能的部分可用
mod(pandalone.xleash):一种用于围绕 Excel 表格的矩形区域“抛绳”的迷你语言。
mod(pandalone.mappings):可以用于索引的分层字符串对象,便于在以后阶段重命名键和列名。
我们的目标是简化从松散耦合的 组件 组成 工程模型 的过程。最初设想为围绕 Pandas 的 间接框架 与 依赖关系解析器 相结合,每个模型都应该自动适应并处理可用的值,并允许对访问它们的路径进行 重映射,以便在无需修改组件代码的情况下运行重命名/移动的 值树。
这是一个开源库,用 Python-3.6+ 编写并测试,支持 Windows 和 Linux。
介绍
概述
在最基本的层面上,任何数据处理的“执行”或“运行”都可以这样理解
.--------------. _____________ .-------------. ; DataTree ; | | ; DataTree ; ;--------------; ==> | <cfunc_1> | ==> ;--------------; ; /some/data ; | <cfunc_2> | ; /some/data ; ; /some/other ; | ... | ; /some/other ; ; /foo/bar ; |_____________| ; /foo/bar ; '--------------' '--------------.
数据树 可以来自 json、hdf5、excel 工作簿或纯字典和列表。其值是字符串和数字、numpy 列表、pandas 或 xray 数据集等。
组件函数 必须遵守以下简单签名
cfunc_do_something(pandelone, datatree)
并且不能返回任何值,只需在数据树中读取和写入。
这是一个简单的组件函数
def cfunc_standardize(pandelone, datatree): pin, pon = pandelone.paths(), df = datatree.get(pin.A) df[pon.A.B_std] = df[pin.A.B] / df[pin.A.B].std()
注意使用标记为输入或输出的 可重定位路径。
TODO:在教程中继续粗糙示例…
快速入门
程序运行在 Python-3.5+ 上,需要 numpy、pandas 以及(可选)win32 库及其 本地后端。
pip install pandalone ## Use `--pre` if version-string has a build-suffix.
… 但可能您还需要以下内容才能使 xleash 正常工作
pip install pandalone[xlrd]
所有“额外内容”都是:test, doc, excel, pandas, xlrd, dev, all
如果您需要从 master 分支获取最新版本
pip install git+https://github.com/pandalone/pandalone.git
或者要安装开发模式,包括所有开发所需的依赖项,以及使用 black 自动格式化 python 代码的 pre-commit 钩子,请从远程仓库克隆本地项目,并运行
pip install -e <pandalone-dr>[dev]
pre-commit install
项目文件和文件夹
以下是项目的文件和文件夹列表
+--pandalone/ ## (package) Python-code +--tests/ ## (package) Test-cases +--doc/ ## Documentation folder +--setup.py ## (script) The entry point for `setuptools`, installing, testing, etc +--requirements/ ## (txt-files) Various pip and conda dependencies. +--README.rst +--CHANGES.rst +--AUTHORS.rst +--CONTRIBUTING.rst +--LICENSE.txt
用法
目前该库的两个部分可用:mod(pandalone.xleash) 和 mod(pandalone.mappings)
GUI 使用
要快速探索数据树的结构并运行实验,只需运行
$ pandalone gui
Excel 使用
在 Windows 和 OS X 中,您可以使用出色的 xlwings 库使用 Excel 文件为实验提供输入和输出。
要创建当前目录下必要的模板文件,应输入
$ pandalone excel
您也可以输入 samp(独立 Excel {file_path}) 来指定不同的目标路径。
[待定]
Python 使用
以下给出了一个示例 Python REPL(读取-评估-打印循环)示例命令,用于设置和运行一个 实验。
首先运行命令(python)或命令(ipython),尝试导入项目以检查其版本
代码块
>>> import pandalone >>> pandalone.__version__ ## Check version once more. '0.5.0' >>> pandalone.__file__ ## To check where it was installed. # doctest: +SKIP /usr/local/lib/site-package/pandalone-...
如果一切正常,创建 数据树 来保存输入数据(字符串和数字)。您可以通过使用以下方法组装数据树:
序列,
字典,
类(pandas.DataFrame),
类(pandas.Series),以及
其他数据树的 URI 引用。
[待定]
参与项目
该项目托管在 github 上。要提供有关错误和问题的反馈,或有关增强功能的问题和请求,请使用 github 的问题跟踪器。
源代码和依赖关系
要参与开发,您需要一个 POSIX 环境,才能完全构建它(Linux、OSX 或 Cygwin 在 Windows 上)。
首先,您需要下载最新的源代码
$ git clone https://github.com/pandalone/pandalone.git pandalone.git
$ cd pandalone.git
Liclipse IDE
在源代码中,有两个用于综合 LiClipse IDE 的示例文件
文件(eclipse.project)
文件(eclipse.pydevproject)
删除 eclipse 前缀(但保留点(.)),然后从 Eclipse 的 文件 菜单导入为“现有项目”。
另一个问题是由于 LiClipse 包含其自己的 Git、EGit 实现,它与 Unix 符号链接(如文件(docs/docs))有严重的交互,并且在新鲜检出后会检测到工作目录的变化。要解决此问题,右键单击上述文件选择(属性 -> 团队 -> 高级 -> 假设未更改)
然后您可以使用文件(setup.py)脚本来 `开发模式` 安装所有项目依赖项
$ python setup.py --help ## Get help for this script.
Common commands: (see '--help-commands' for more)
setup.py build will build the package underneath 'build/'
setup.py install will install the package
Global options:
--verbose (-v) run verbosely (default)
--quiet (-q) run quietly (turns verbosity off)
--dry-run (-n) don't actually do anything
...
$ python setup.py develop ## Also installs dependencies into project's folder.
$ python setup.py build ## Check that the project indeed builds ok.
现在您应该运行测试用例,以检查源代码是否良好
$ python setup.py test
注意
上述命令在项目文件夹和 `虚拟环境` 中安装了依赖项。这就是为什么所有构建和测试操作都必须通过 samp(python setup.py {some_cmd}) 进行。
如果您正在处理安装问题,并且/或者您想要永久安装依赖包,您必须 停用 虚拟环境,并将它们安装到您的 基础 Python 环境中
$ deactivate
$ python setup.py develop
甚至尝试更 `永久` 的安装模式
$ python setup.py install # May require admin-rights
设计
请参阅 架构实时文档。
常见问题解答
为什么还需要另一个 XXX?YYY 又如何?
以下是与已知相关的 Python 项目
OpenMDAO:它影响了 pandalone 的设计。计划通过将其数据类型转换为它来互操作。但它仅支持 Python-2,其架构需要程序员关注(没有 setup.py、没有官方测试用例)。
PyDSTool:由于它不涉及IO和数据依赖,因此没有重叠。还计划与它交互(一旦我们更好地掌握它)。它有一些文档问题,但他们正在努力解决。
xray:Pandas的高维版本;数据树原则上应该与“xray”一起工作。
Blaze:NumPy和Pandas与大数据的接口;数据树原则上应该与“blaze”一起工作。
netCDF4:类似于
的层次文件数据格式;数据树原则上可以源自“netCDF4”。 hdf5:层次文件数据格式,Pandas原生支持;数据树原则上可以源自“netCDF4”。
在构建此库时,您审查了哪些其他项目/想法?
bubbles ETL:主要用于分类数据的处理管道。
数据协议:
Celery:使用消息传递在单个或多个工作服务器上执行分布式异步任务,使用多进程、Eventlet或gevent。
Fuzzywuzzy和Jellyfish:Python中的模糊字符串匹配。用于编写可以读取粗略已知的列名的代码。
“其他人的混乱数据(以及如何不讨厌它)”,2015年PyCon(加拿大)Mali Akmanalp的演讲。
术语表
标准
data-tree The *container* of data consumed and produced by a :term`model`, which may contain also the model. Its values are accessed using **path** s. It is implemented by class(`pandalone.pandata.Pandel`) as a mergeable stack of **JSON-schema** abiding trees of strings and numbers, formed with: - sequences, - dictionaries, - mod(`pandas`) instances, and - URI-references. value-tree That part of the **data-tree** that relates only to the I/O data processed. model A collection of **component** s and accompanying **mappings**. component Encapsulates a data-transformation function, using **path** to refer to its inputs/outputs within the **value-tree**. path A `/file/like` string functioning as the *id* of data-values in the **data-tree**. It is composed of **step**, and it follows the syntax of the **JSON-pointer**. step pstep path-step The parts between between two conjecutive slashes(`/`) within a **path**. The class(`Pstep`) facilitates their manipulation. pmod pmods pmods-hierarchy mapping mappings Specifies a transformation of an "origin" path to a "destination" one (also called as "from" and "to" paths). The mapping always transforms the *final* path-step, and it can either *rename* or *relocate* that step, like that:: ORIGIN DESTINATION RESULT_PATH ------ ----------- ----------- /rename/path foo --> /rename/foo ## renaming /relocate/path foo/bar --> /relocate/foo/bar ## relocation /root a/b/c --> /a/b/c ## Relocates all /root sub-paths. The hierarchy is formed by class(`Pmod`) instances, which are build when parsing the **mappings** list, above. JSON-schema The `JSON schema <https://json-schema.fullstack.org.cn/>`_ is an `IETF draft <http://tools.ietf.org/html/draft-zyp-json-schema-03>`_ that provides a *contract* for what JSON-data is required for a given application and how to interact with it. JSON Schema is intended to define validation, documentation, hyperlink navigation, and interaction control of JSON data. You can learn more about it from this `excellent guide <http://spacetelescope.github.io/understanding-json-schema/>`_, and experiment with this `on-line validator <http://www.jsonschema.net/>`_. JSON-pointer JSON Pointer(rfc(`6901`)) defines a string syntax for identifying a specific value within a JavaScript Object Notation (JSON) document. It aims to serve the same purpose as *XPath* from the XML world, but it is much simpler.
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。