Bug: pct_change with frequency set as 'BM' throws value error · Issue #28664 · pandas-dev/pandas (original) (raw)
Code Sample, a copy-pastable example if possible
import pandas as pd
import random
import numpy as np
Creating the time-series index
n=60
index = pd.date_range('01/13/2020', periods = 70,freq='D')
Creating the dataframe
df = pd.DataFrame({"A":np.random.uniform(low=0.5, high=13.3, size=(70,)),
"B":np.random.uniform(low=10.5, high=45.3, size=(70,)),
"C":np.random.uniform(low=70.5, high=85, size=(70,)),
"D":np.random.uniform(low=50.5, high=65.7, size=(70,))}, index = index)
df.pct_change(freq='BM')
Problem description
For a time-series data, the df.pct_change(freq='BM') doesn't works and throws following error.
ValueError: cannot reindex from a duplicate axis
Expected Output
df.asfreq('BM').pct_change()
Output of pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.6.3.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 9, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
pandas : 0.25.1
numpy : 1.15.4
pytz : 2017.2
dateutil : 2.6.1
pip : 18.0
setuptools : 39.1.0
Cython : 0.26.1
pytest : 5.1.2
hypothesis : None
sphinx : 1.6.3
blosc : None
feather : None
xlsxwriter : 1.0.2
lxml.etree : 4.1.0
html5lib : 0.9999999
pymysql : None
psycopg2 : 2.7.5 (dt dec pq3 ext lo64)
jinja2 : 2.9.6
IPython : 6.1.0
pandas_datareader: None
bs4 : 4.6.0
bottleneck : 1.2.1
fastparquet : None
gcsfs : None
lxml.etree : 4.1.0
matplotlib : 2.1.0
numexpr : 2.6.2
odfpy : None
openpyxl : 2.4.8
pandas_gbq : None
pyarrow : 0.8.0
pytables : None
s3fs : None
scipy : 1.0.0
sqlalchemy : 1.1.13
tables : 3.4.2
xarray : 0.10.7
xlrd : 1.1.0
xlwt : 1.3.0
xlsxwriter : 1.0.2