Skip to main content

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)

Uploaded Source

Built Distribution

pandasmore-0.0.1-py3-none-any.whl (10.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page