votes up 4

PeriodIndex given. Check the `freq` attribute instead of using infer_freq.

github stars 30911
Exception Class:

Raise code

index = values

    inferer: _FrequencyInferer

    if not hasattr(index, "dtype"):
    elif is_period_dtype(index.dtype):
        raise TypeError(
            "PeriodIndex given. Check the `freq` attribute "
            "instead of using infer_freq."
    elif is_timedelta64_dtype(index.dtype):
        # Allow TimedeltaIndex and TimedeltaArray
        inferer = _TimedeltaFrequencyInferer(index, warn=warn)
        return inferer.get_freq()

😲  Walkingbet is Android app that pays you real bitcoins for a walking. Withdrawable real money bonus is available now, hurry up! 🚶

Ways to fix

votes up 3 votes down

Summary: use DatetimeIndex or TimedeltaIndex instead of PeriodIndex as the data type for the "index" function parameter

Code to reproduce (WRONG):

from pandas.tseries import frequencies
import pandas as pd

idx = pd.PeriodIndex(year=[2000, 2002], quarter=[1, 3])

Working version (Fixed)

from pandas.tseries import frequencies
import pandas as pd

idx = pd.date_range(start='2020/01/01', end='2020/08/30', periods=30) # <--- Fix this is an example from the The date_range function return DatatimeIndex which is expected for the "index" parameter that is passed to infer_freq function 

Jun 03, 2021 phoang88 answer
phoang88 615

Add a possible fix

Please authorize to post fix