pandas series use truncate get specified hours, minutes and seconds?

xin.chen

my data

data= [{"content": "11", "title": "刘德华", "info": "2020-01-13 08:56:54", "time": 1578877014},
                  {"content": "22", "title": "刘德", "info": "2020-01-24", "time": 1579877014},
                  {"content": "33", "title": "apple", "info": "2020-02-28", "time": 1582877014},
                  {"content": "55", "title": "app", "info": "2020-02-17", "time": 1581877014},
                  {"content": "66", "title": "appstore", "info": "2019-06-30", "time": 1561877014},
                  {"content": "44", "title": "banana", "info": "2020-02-28", "time": 1582876014},
                  {"content": "aa", "title": "banana", "info": "2020-03-12 eee", "time": 1584000882},
                  {"content": "bb", "title": "Thursday data", "info": "2018-03-12 vvvv", "time": 1520842482},
                  {"content": "cc", "title": "banana", "info": "2020-03-14 xxx", "time": 1584154305},
                  {"content": "cc", "title": "banana", "info": "2019-03-14 aa", "time": 1552531905},
                  {"content": "cc", "title": "Thursday data", "info": "2020-03-19 data", "time": 1584586305},
                  {"content": "cc", "title": "Thursday data", "info": "2019-11-07 aaa", "time": 1573095105},

                  ]

i want get 2020-01-13 08:00:00 to 2020-01-13 10:56:54 i try use truncate but get is None

s=pd.Series(data,index=pd.to_datetime([i['time'] for i in data],utc=True,  unit='s').tz_convert('Asia/Shanghai'))
s.truncate("2020-01-13 08:00:00","2020-01-13 10:56:54").tolist()
>>> []

but use truncate for 2020-01-13 to 2020-01-13 10:56:54 has get data

data],utc=True,  unit='s').tz_convert('Asia/Shanghai'))
s.truncate("2020-01-13","2020-01-13 10:56:54").tolist()
>>> [{"content": "11", "title": "刘德华", "info": "2020-01-13 08:56:54", "time": 1578877014}]

params:before and after must be 2020-01-13 10:56:54

jezrael

I believe you need slicing:

s1 = s["2020-01-13 08:00:00":"2020-01-13 10:56:54"]
print (s1)

2020-01-13 08:56:54+08:00    {'content': '11', 'title': '刘德华', 'info': '202...
dtype: object

I truncate and got few errors, then I correct them, but I also got no value, I guess it is bug.

s=pd.Series(data,index=pd.to_datetime([i['time'] for i in data],utc=True,  unit='s').tz_convert('Asia/Shanghai')).sort_index()
s1 = s.truncate(pd.to_datetime("2020-01-13 08:00:00").tz_localize('utc').tz_convert('Asia/Shanghai'),
                pd.to_datetime("2020-01-13 10:56:54").tz_localize('utc').tz_convert('Asia/Shanghai')).tolist()

EDIT: Also checked docs and it explain why working same selecting like "2020-01-13 00:00:00" and "2020-01-13:

A truncate() convenience function is provided that is similar to slicing. Note that truncate assumes a 0 value for any unspecified date component in a DatetimeIndex in contrast to slicing which returns any partially matching dates

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Seconds, minutes and hours since a date

분류에서Dev

How to get difference between 2 dates in number of days,hours,minutes and seconds

분류에서Dev

How to convert minutes to hours and minutes (without days)

분류에서Dev

Remove hours from time series

분류에서Dev

mysql: automatically convert seconds to hours for some columns

분류에서Dev

JQuery TimeCircles - display minutes and seconds in one circle

분류에서Dev

converting seconds to minutes but without changing the format

분류에서Dev

Get previous 10 seconds

분류에서Dev

Only display hours if time is greater than 60 minutes

분류에서Dev

How moment.js works with declination minutes and hours?

분류에서Dev

Countdown in hrs/minutes/seconds in php function using javascript

분류에서Dev

Expand a time series by specified time lengths in R

분류에서Dev

Resample Time Series in pandas

분류에서Dev

Convert pandas series into integers

분류에서Dev

Get a web page every 5 hours

분류에서Dev

Days : Minutes : Hours 형식의 DateTime 차이를 얻는 방법

분류에서Dev

Pandas - Extracting data from Series

분류에서Dev

Time Series using numpy or pandas

분류에서Dev

Pandas series - recording numerical changes

분류에서Dev

How can I see which process hangs my Banana-pi for few seconds every couple of minutes?

분류에서Dev

Block/prevent command if it has been executed within the last x seconds/minutes

분류에서Dev

pandas.core.series.Series에 제목 추가

분류에서Dev

rails wants to use PG but mysql is specified

분류에서Dev

use regular expression to prase specified protocol

분류에서Dev

use regular expression to prase specified protocol

분류에서Dev

Automatically get the time taking day light saving hours into account

분류에서Dev

Get the first occurence of the result in each specified group

분류에서Dev

How to get image in specified size given in parameter?

분류에서Dev

Update pandas DataFrame Multilevel Index with a Series?

Related 관련 기사

  1. 1

    Seconds, minutes and hours since a date

  2. 2

    How to get difference between 2 dates in number of days,hours,minutes and seconds

  3. 3

    How to convert minutes to hours and minutes (without days)

  4. 4

    Remove hours from time series

  5. 5

    mysql: automatically convert seconds to hours for some columns

  6. 6

    JQuery TimeCircles - display minutes and seconds in one circle

  7. 7

    converting seconds to minutes but without changing the format

  8. 8

    Get previous 10 seconds

  9. 9

    Only display hours if time is greater than 60 minutes

  10. 10

    How moment.js works with declination minutes and hours?

  11. 11

    Countdown in hrs/minutes/seconds in php function using javascript

  12. 12

    Expand a time series by specified time lengths in R

  13. 13

    Resample Time Series in pandas

  14. 14

    Convert pandas series into integers

  15. 15

    Get a web page every 5 hours

  16. 16

    Days : Minutes : Hours 형식의 DateTime 차이를 얻는 방법

  17. 17

    Pandas - Extracting data from Series

  18. 18

    Time Series using numpy or pandas

  19. 19

    Pandas series - recording numerical changes

  20. 20

    How can I see which process hangs my Banana-pi for few seconds every couple of minutes?

  21. 21

    Block/prevent command if it has been executed within the last x seconds/minutes

  22. 22

    pandas.core.series.Series에 제목 추가

  23. 23

    rails wants to use PG but mysql is specified

  24. 24

    use regular expression to prase specified protocol

  25. 25

    use regular expression to prase specified protocol

  26. 26

    Automatically get the time taking day light saving hours into account

  27. 27

    Get the first occurence of the result in each specified group

  28. 28

    How to get image in specified size given in parameter?

  29. 29

    Update pandas DataFrame Multilevel Index with a Series?

뜨겁다태그

보관