A panel data evaluator.
Project description
panelexpr
A simple panel data evaluator
Installation
$ pip install panelexpr
Usage
Sample Data
sample_zh_2.csv:
| Date | windcode | Open | High | Low | Close | Volume |
|---|---|---|---|---|---|---|
| 20170913 | 000001.SZ | 1221.488009 | 1226.803448 | 1205.54169 | 1215.109481 | 668237.42 |
| 20170914 | 000001.SZ | 1215.109481 | 1232.118888 | 1194.910811 | 1203.415514 | 883087.77 |
| 20170915 | 000001.SZ | 1200.22625 | 1203.415514 | 1185.34302 | 1200.22625 | 646094.81 |
| 20170918 | 000001.SZ | 1195.973899 | 1203.415514 | 1190.658459 | 1195.973899 | 607612.96 |
| 20170919 | 000001.SZ | 1195.973899 | 1205.54169 | 1177.901404 | 1183.216844 | 764212.62 |
| 20170913 | 000002.SZ | 3473.691392 | 3576.666433 | 3431.128374 | 3536.849417 | 467463.77 |
| 20170914 | 000002.SZ | 3539.595418 | 3852.639543 | 3508.016405 | 3783.989516 | 1150696.14 |
| 20170915 | 000002.SZ | 3775.751513 | 4149.207662 | 3771.632511 | 4022.891612 | 1550495.61 |
| 20170918 | 000002.SZ | 3983.074596 | 4083.303636 | 3843.028539 | 3849.893542 | 1063043.07 |
| 20170919 | 000002.SZ | 3881.472555 | 4132.731656 | 3858.131546 | 3950.122582 | 1196308.5 |
load data
import pandas as pd
data = pd.read_csv("../data/sample_zh_2.csv")
Calculation
import panelexpr as pe
pe.eval("ma(Open, 2)", data=data, group_tag="windcode")
# equivalent to
data.groupby("windcode").rolling(2).mean()["Open"].reset_index(drop=True).rename()
Output:
0 NaN
1 1218.298745
2 1207.667866
3 1198.100075
4 1195.973899
5 NaN
6 3506.643405
7 3657.673466
8 3879.413054
9 3932.273575
dtype: float64
User defined operator
from panelexpr import TimeSeriesOperator
class MyMovingAverageOperator(TimeSeriesOperator):
def eval(self, series: pd.Series, window) -> pd.Series: # all udo must implement this method
s = series.rolling(window).mean()
return s
pe.register("my_ma", MyMovingAverageOperator) # register the operator
pe.eval("my_ma(Open, 2)", data=data, group_tag="windcode")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
panelexpr-0.1.0.tar.gz
(11.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
panelexpr-0.1.0-py3-none-any.whl
(13.3 kB
view details)
File details
Details for the file panelexpr-0.1.0.tar.gz.
File metadata
- Download URL: panelexpr-0.1.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb04d58abba8ad0db72365b99f42227d1012608fc9ec5ce3c26140d29fb74d60
|
|
| MD5 |
7bc34fc81d761b9512866156fe0b0bb7
|
|
| BLAKE2b-256 |
db51198d88a397f35ca2421c4217b046a061edfafd1b12576c28197148203d27
|
File details
Details for the file panelexpr-0.1.0-py3-none-any.whl.
File metadata
- Download URL: panelexpr-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19a77b641799c44208b950f14dfe1b0a7c526e1ef64babd816b051bb279682d9
|
|
| MD5 |
05c41af22d9c21f849dbe61741c1a9de
|
|
| BLAKE2b-256 |
40f5bd35bdf5ea53b07e44d4549536865f6c66f412416d9881ae5ec0c99712b8
|