4

I use the history.DataFrame.last('10s) in a dataframe of 5h data (300 rows for every minute) and gives me the whole DataFrame.

On the other hand the command history.between_time('22:06:00','22:10:00') gives me the correct part.

Do you naybe know what is the problem? Thank you.

The complete dataframe and the results follow:

    history = 

                           time     low    high    open   close      volume
Index                                                                      
2020-04-18 22:14:00  1587248040  170.27  170.32  170.27  170.32   32.788304
2020-04-18 22:13:00  1587247980  170.20  170.27  170.27  170.20    2.495578
2020-04-18 22:12:00  1587247920  170.20  170.27  170.20  170.27   28.454885
2020-04-18 22:11:00  1587247860  170.10  170.21  170.10  170.21   97.663555
2020-04-18 22:10:00  1587247800  169.80  170.10  169.84  169.94  189.118185
                        ...     ...     ...     ...     ...         ...
2020-04-18 17:15:00  1587230100  167.56  167.73  167.56  167.72   15.257272
2020-04-18 17:14:00  1587230040  167.63  167.72  167.67  167.72    0.405094
2020-04-18 17:13:00  1587229980  167.57  167.61  167.57  167.61   23.075999
2020-04-18 17:12:00  1587229920  167.49  167.61  167.61  167.60    9.606858
2020-04-18 17:11:00  1587229860  167.60  167.73  167.60  167.60   53.414672

[300 rows x 6 columns]

history.last('10s')
Out[84]: 
                           time     low    high    open   close      volume
Index                                                                      
2020-04-18 22:14:00  1587248040  170.27  170.32  170.27  170.32   32.788304
2020-04-18 22:13:00  1587247980  170.20  170.27  170.27  170.20    2.495578
2020-04-18 22:12:00  1587247920  170.20  170.27  170.20  170.27   28.454885
2020-04-18 22:11:00  1587247860  170.10  170.21  170.10  170.21   97.663555
2020-04-18 22:10:00  1587247800  169.80  170.10  169.84  169.94  189.118185
                        ...     ...     ...     ...     ...         ...
2020-04-18 17:15:00  1587230100  167.56  167.73  167.56  167.72   15.257272
2020-04-18 17:14:00  1587230040  167.63  167.72  167.67  167.72    0.405094
2020-04-18 17:13:00  1587229980  167.57  167.61  167.57  167.61   23.075999
2020-04-18 17:12:00  1587229920  167.49  167.61  167.61  167.60    9.606858
2020-04-18 17:11:00  1587229860  167.60  167.73  167.60  167.60   53.414672

[300 rows x 6 columns]

history.between_time('22:06:00','22:10:00')
Out[82]: 
                           time     low    high    open   close      volume
Index                                                                      
2020-04-18 22:10:00  1587247800  169.80  170.10  169.84  169.94  189.118185
2020-04-18 22:09:00  1587247740  169.90  169.97  169.90  169.97   11.503376
2020-04-18 22:08:00  1587247680  169.65  169.90  169.65  169.90  103.496717
2020-04-18 22:07:00  1587247620  169.63  169.65  169.65  169.63    2.708217
2020-04-18 22:06:00  1587247560  169.65  169.68  169.68  169.65    6.306080

1 Answer 1

5

Your index needs to be sorted in ascending order.

history.sort_index().last('10s')                                                                                                                                                                                                    
#                            time     low    high    open   close     volume
# Index                                                                     
# 2020-04-18 22:14:00  1587248040  170.27  170.32  170.27  170.32  32.788304

Your index looks to be reversed right now. So without the sort_index(), the last row actually has the smallest index time. All of the other times are after that, while last() is looking to remove things that are more than 10 seconds before the reference time.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.