0

I have a pandas dataframe data with three frequencies (in some data there are even more)

    Date        value frequency  
23/10/2016 20:31    0    00:06
23/10/2016 20:36    0.5  00:05
23/10/2016 20:43    0.2  00:07
23/10/2016 20:49    0.1  00:06
23/10/2016 20:54    0    00:05
23/10/2016 21:00    2    00:06
23/10/2016 21:06    4    00:06
23/10/2016 21:12    5    00:06
23/10/2016 21:18    6    00:06
23/10/2016 21:24    10   00:06
23/10/2016 21:31    0    00:07
23/10/2016 21:37    0    00:06
23/10/2016 21:43    0    00:06
23/10/2016 21:48    7    00:05
23/10/2016 21:55    10   00:07
23/10/2016 22:00    0    00:05
23/10/2016 22:06    0    00:06
23/10/2016 22:12    0    00:06
23/10/2016 22:18    0    00:06
23/10/2016 22:25    0    00:07
23/10/2016 22:31    0    00:06

What I want of this data is I want to re sample to 15 mins, is there a way that panda handle multiple frequency data while creating index and that can be used for re-sampling the data.

I tried like this :

df=my_data_frame
df.index=df['Date']
df.resample('15T').sum()

This is giving me weird result like this :

Date                value
10/01/2016 22:15    0
10/01/2016 22:30    0
10/01/2016 22:45    0
10/01/2016 23:00    0
10/01/2016 23:15    0
10/01/2016 23:30    0
10/01/2016 23:45    0
11/01/2016 0:00 
11/01/2016 0:15 
11/01/2016 0:30 
11/01/2016 0:45 
11/01/2016 1:00 
11/01/2016 1:15 
11/01/2016 1:30 
11/01/2016 1:45 
11/01/2016 2:00 
11/01/2016 2:15 
11/01/2016 2:30 
11/01/2016 2:45 
11/01/2016 3:00 

Index has been changed... ?

8
  • 1
    What's your expected output? Commented Jul 9, 2017 at 23:25
  • 1
    it gave weird result how ? what's your expected result ? Commented Jul 9, 2017 at 23:40
  • @Allen, I want 15 min re-sample data. I have also shown the result what I got after I re sample. I have a feeling that there might be a problem while setting index. Commented Jul 9, 2017 at 23:57
  • Can you add the output of df.head().to_dict() here? Commented Jul 10, 2017 at 0:16
  • @ayhan, here is goes {Timestamp('2016-01-10 00:00:00', freq='15T'): 0.0, Timestamp('2016-01-10 00:15:00', freq='15T'): 0.0, Timestamp('2016-01-10 00:30:00', freq='15T'): 0.0, Timestamp('2016-01-10 00:45:00', freq='15T'): 0.0, Timestamp('2016-01-10 01:00:00', freq='15T'): 0.0}' Commented Jul 10, 2017 at 0:25

1 Answer 1

1

Pretty sure your dates are strings

df.index = pd.to_datetime(df.Date)
df.value.resample('15T').sum()
Sign up to request clarification or add additional context in comments.

2 Comments

@ayhan not sure. I'll test it out
I even tried this df.index=pd.DatetimeIndex(df['Date']). This is also giving me the same result. I have data only for September, but after I re-sample I am getting data for other months as well.

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.