Pandas - Data Series - TypeError: Index must be DatetimeIndex

后端 未结 1 738
日久生厌
日久生厌 2021-01-25 06:13

C is a Data series with shape of (10000000, ) with dtypes of dtype(< M8[ns]). I want to create a dataseries which only contain one hour of C.

 c.between_time         


        
相关标签:
1条回答
  • 2021-01-25 06:31

    Try creating a dataframe by initializing an empty dataframe.
    I created a sample of 3 dummy times in Series

    import pandas as pd  
    C = pd.Series(['22:00:00','22:30:00','23:00:00'])
    
    df = pd.DataFrame()
    df['C'] = C
    
    #set index to the obervations after converting them to type datetimeIndex
    df.index = pd.to_datetime(C)
    print df
    
    print df.between_time(df['C'][0],df['C'][2])
    
    0 讨论(0)
提交回复
热议问题