Extends pandas with common functions used in finance and economics research
Project description
pandasmore
The full documentation site is here.
Here is a short description of some of the main functions (see below for more details):
panel_setup
: cleans up dates and panel id’s and sets them as the index (panel id, period date)lag
: robust lagging that accounts for panel structure, unsorted or duplicate dates, or gaps in the time-series
Install
pip install pandasmore
How to use
First, we set up an example dataset to showcase the functions in this module.
import pandas as pd
import numpy as np
from pandasmore.core import *
df = pd.DataFrame(np.random.rand(8,2),
columns=list('AB'),
index=pd.MultiIndex.from_product(
[[1,2],
pd.to_datetime(['2010-01','2010-02','2010-02','2010-04']
).to_period('M')],
names=['permno','Mdate']))
df
A | B | ||
---|---|---|---|
permno | Mdate | ||
1 | 2010-01 | 0.065783 | 0.204804 |
2010-02 | 0.394326 | 0.129398 | |
2010-02 | 0.311802 | 0.882613 | |
2010-04 | 0.573854 | 0.107920 | |
2 | 2010-01 | 0.407374 | 0.270169 |
2010-02 | 0.345566 | 0.931718 | |
2010-02 | 0.042698 | 0.989230 | |
2010-04 | 0.801888 | 0.574477 |
lag(df['A'])
permno Mdate
1 2010-01 NaN
2010-02 0.065783
2010-02 NaN
2010-04 NaN
2 2010-01 NaN
2010-02 0.407374
2010-02 NaN
2010-04 NaN
Name: A_lag1, dtype: float64
lag(df['A'], fast=False)
permno Mdate
1 2010-01 NaN
2010-02 0.065783
2010-02 0.065783
2010-04 NaN
2 2010-01 NaN
2010-02 0.407374
2010-02 0.407374
2010-04 NaN
Name: A_lag1, dtype: float64
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pandasmore-0.0.1.tar.gz
(21.4 kB
view hashes)
Built Distribution
pandasmore-0.0.1-py3-none-any.whl
(10.5 kB
view hashes)
Close
Hashes for pandasmore-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb0a14ac6fca84704c85849aaa7c355db1a6ee9d5eb1a8dfc26812116365de2b |
|
MD5 | 949c9bf6c8a62b6b561f6350b808dabd |
|
BLAKE2b-256 | 908cfe9d0bdcf3066bc4e55445ab904c45f61c79858581a463f1ec52dadd8223 |