熊猫时间序列数据的快速存储
PyStore的Python项目详细描述
pystore-熊猫时间序列数据的快速数据存储
PyStore是一个简单的(但强大的) 熊猫数据帧的数据存储,虽然它可以存储任何熊猫对象, 它的设计考虑了存储timeseries数据。
它建在Pandas,Numpy, Dask,和Parquet (通过Fastparquet) 为python开发人员提供易于使用的数据存储 每台客户机每秒查询数百万行。
==>;签出this Blog post 对于pystore背后的推理和哲学,以及一个带有代码示例的详细教程。
==>;以Jupyter笔记本格式跟随this PyStore tutorial。
快速启动
安装pystore
使用pip安装
$ pip install PyStore
或使用以下命令进行升级:
$ pip install PyStore --upgrade --no-cache-dir
安装说明: 如果没有安装Snappy(压缩/解压缩库),则需要 你需要install it first。
使用pystore
#!/usr/bin/env python# -*- coding: utf-8 -*-importpystoreimportquandl# Set storage path (optional, default is `~/pystore`)pystore.set_path("~/pystore")# List storespystore.list_stores()# Connect to datastore (create it if not exist)store=pystore.store('mydatastore')# List existing collectionsstore.list_collections()# Access a collection (create it if not exist)collection=store.collection('NASDAQ')# List items in collectioncollection.list_items()# Load some data from Quandlaapl=quandl.get("WIKI/AAPL",authtoken="your token here")# Store the first 100 rows of the data in the collection under "AAPL"collection.write('AAPL',aapl[:100],metadata={'source':'Quandl'})# Reading the item's dataitem=collection.item('AAPL')data=item.data# <-- Dask dataframe (see dask.pydata.org)metadata=item.metadatadf=item.to_pandas()# Append the rest of the rows to the "AAPL" itemcollection.append('AAPL',aapl[100:])# Reading the item's dataitem=collection.item('AAPL')data=item.datametadata=item.metadatadf=item.to_pandas()# --- Query functionality ---# Query avaialable symbols based on metadatacollection.list_items(some_key='some_value',other_key='other_value')# --- Snapshot functionality ---# Snapshot a collection# (Point-in-time named reference for all current symbols in a collection)collection.create_snapshot('snapshot_name')# List available snapshotscollection.list_snapshots()# Get a version of a symbol given a snapshot namecollection.item('AAPL',snapshot='snapshot_name')# Delete a collection snapshotcollection.delete_snapshot('snapshot_name')# ...# Delete the item from the current versioncollection.delete_item('AAPL')# Delete the collectionstore.delete_collection('NASDAQ')
概念
pystore提供了名空间的collections数据。 这些集合允许通过source、user或其他度量对数据进行bucketing (例如频率:一天结束;分钟酒吧等)。每个集合(或命名空间) 映射到包含每个项(例如符号)的分区parquet文件的目录。
一个很好的做法是创建看起来像这样的集合:
- collection.eod
- collection.one分钟
要求
- python>;=3.5
- 熊猫
- 努比
- 达斯克
- 快拼花
- Snappy(谷歌的压缩/解压库)
- 多任务处理
pystore经过测试可以在类似于*nix的系统上工作,包括macos。
依赖关系:
pystore使用Snappy, 来自google的快速高效的压缩/解压库。 在安装pystore之前,您需要在系统上安装snapy。
*有关详细信息,请参见python-snappyGithub repo。
*nix系统:
- 公寓:sudo apt-get install libsnappy-dev
- 转速:sudo yum install libsnappy-devel
macos:
首先,使用Homebrew:
$ brew install snappy
然后,使用conda:
$ conda install python-snappy -c conda-forge
…或者,使用pip:
$ CPPFLAGS="-I/usr/local/include -L/usr/local/lib" pip install python-snappy
windows:
windows用户应该签出Snappy for Windows和this Stackoverflow post以获取有关安装snappy和python-snappy的帮助。
许可证
pystore是根据apache许可证(2.0版)授权的。其副本包含在license.txt中。
我对你在Pystore的经历很感兴趣。 请给我一张便条,上面有你的任何反馈。
欢迎投稿!
-ran唤醒