Skip to content

I can't convert 1H OHLC data into monthly data with a specific time by loffset #19422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yomoko opened this issue Jan 27, 2018 · 4 comments
Closed
Labels
Needs Info Clarification about behavior needed to assess issue

Comments

@yomoko
Copy link

yomoko commented Jan 27, 2018

#13218
#13933
With regard to the above issues, I have the same problem. I need to convert 1 hour to monthly data, the requirement is that I need to set the beginning time interval to 17:00.

ohlc_dict = {'open':'first', 'high':'max', 'low':'min', 'close': 'last'}
df = df.resample('1M', loffset='17H',closed='left',label='left').agg(ohlc_dict)
I specified the time by loffset='17H' already, it just changed time label to 17:00, but it still took the Open Price from 00:00 instead of 17:00. What can I do to the get open price at 17:00 instead of 00:00? Thanks.

@yomoko yomoko changed the title I can't convert 1H OHLC data into monthly data with a specific time using Python I can't convert 1H OHLC data into monthly data with a specific time by loffset Jan 27, 2018
@chris-b1
Copy link
Contributor

please show a reproducible example

@TomAugspurger TomAugspurger added the Needs Info Clarification about behavior needed to assess issue label Jan 30, 2018
@yomoko
Copy link
Author

yomoko commented Jan 31, 2018

@TomAugspurger Let's make it simpler. If I am resampling from 1 hour to 1 month, is it possible to specify a base with a different unit such as hours?

@TomAugspurger
Copy link
Contributor

Let us know if you can make an example, http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports

@andreivirtosu
Copy link

see reproducible example below:

>>> df = pd.DataFrame(np.random.rand(60,2), columns=list('AB'), index=pd.date_range('2010-01-01 09:00:00', periods=60, freq='1min'))
>>> df.head()
                            A         B
2010-01-01 09:00:00  0.182271  0.367963
2010-01-01 09:01:00  0.562164  0.465836
2010-01-01 09:02:00  0.836276  0.905308
2010-01-01 09:03:00  0.397262  0.216895
2010-01-01 09:04:00  0.637719  0.182088
>>> df.resample('15min').agg({'A':'first','B':'last'})
                            A         B
2010-01-01 09:00:00  0.182271  0.759560
2010-01-01 09:15:00  0.187075  0.563832
2010-01-01 09:30:00  0.303773  0.302590
2010-01-01 09:45:00  0.531070  0.493919
>>> df.resample('15min', loffset='5min').agg({'A':'first','B':'last'})
                            A         B
2010-01-01 09:05:00  0.182271  0.759560
2010-01-01 09:20:00  0.187075  0.563832
2010-01-01 09:35:00  0.303773  0.302590
2010-01-01 09:50:00  0.531070  0.493919

Adding the loffset changed the timestamp but the A B columns values were left unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Info Clarification about behavior needed to assess issue
Projects
None yet
Development

No branches or pull requests

4 participants