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 hashes)
Built Distribution
panelexpr-0.1.0-py3-none-any.whl
(13.3 kB
view hashes)
Close
Hashes for panelexpr-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19a77b641799c44208b950f14dfe1b0a7c526e1ef64babd816b051bb279682d9 |
|
MD5 | 05c41af22d9c21f849dbe61741c1a9de |
|
BLAKE2b-256 | 40f5bd35bdf5ea53b07e44d4549536865f6c66f412416d9881ae5ec0c99712b8 |