Bernard Esterhuyse
Bernard Esterhuyse

Reputation: 406

Pandas resample error: resample() got an unexpected keyword argument 'offset'

I'm trying to resample a dataframe, and I would like to offset the data. I'm getting the error:

resample() got an unexpected keyword argument 'offset'

I have tried running the sample code from the pandas documentation.

start, end = '2000-10-01 23:30:00', '2000-10-02 00:30:00'
rng = pd.date_range(start, end, freq='7min')
ts = pd.Series(np.arange(len(rng)) * 3, index=rng)

ts.resample('17min', offset='23h30min').sum()

This results in the same error. I have upgraded pandas to the current latest version ('1.0.3').

Update:

In the documentation, under offset it states "New in version 1.1.0."

Upvotes: 0

Views: 2689

Answers (3)

tgaufa
tgaufa

Reputation: 1

I think this one may help:

ts.shift(1)

Upvotes: 0

Bernard Esterhuyse
Bernard Esterhuyse

Reputation: 406

The solution is to install pandas 1.1.0. The can be done by building pandas from source.

Clone the dev version of pandas from github:

git clone https://github.com/pandas-dev/pandas/releases

Install cython:

pip install cython

cd pandas, and then:

python -m pip install -e . --no-build-isolation --no-use-pep517

Upvotes: 1

Sahith Kurapati
Sahith Kurapati

Reputation: 1715

You've made a small mistake. There is no offset parameter. It is loffset.

See the documentation here (stable version documentation).

So it should be:

rng = pd.date_range(start, end, freq='7min')
ts = pd.Series(np.arange(len(rng)) * 3, index=rng)

ts.resample('17min', loffset='23h30min').sum()

Upvotes: 0

Related Questions