-3

I have a python pandas dataframe named 'Red' with two columns TimeStamp and Red. The index is already set to TimeStamp. Sum() is applied but it aggregated on second based. I need to aggregate on Hourly, Weekly and monthly base. Plz guide, thanks

In [56]: Red.columns 
Out[56]: Index(['TimeStamp', 'Red'], dtype='object') 
In [64]: Red.shape , type(Red) 
Out[64]: ((1381701, 2), pandas.core.frame.DataFrame) 
In [69]: Red.head(5) 
Out[69]: 
       TimeStamp      Red 
0 2017-05-01 00:00:01  1  
1 2017-05-01 00:00:01  1 
2 2017-05-01 00:00:01  1 
3 2017-05-01 00:00:01  1 
4 2017-05-01 00:00:01  1 
In [70]: Red.groupby('TimeStamp').sumfthead(3)
Out[70]:  
      TimeStamp      Red
2017-05-01 00:00:01  16 
2017-05-01 00:00:02  16 
2017-05-01 00:00:03  16  
Anuraag Baishya
  • 874
  • 2
  • 11
  • 26
MAK
  • 57
  • 1
  • 6
  • 1
    Welcome to StackOverflow. Please take the time to read this post on [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on [how to ask a good question](http://stackoverflow.com/help/how-to-ask) may also be useful. – jezrael Apr 24 '18 at 10:45
  • 1
    [Please don't post images of code (or links to them)](http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so-when-asking-a-question) – jezrael Apr 24 '18 at 10:46
  • Ok, I'm new to stackoverflow, thanks for guidance. – MAK Apr 25 '18 at 01:46

1 Answers1

0

It looks like you should use the Series method .resample() once you got a TimeSeriesStamp as index.

Look at the documentation for more detail. https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.resample.html

gonzalo mr
  • 144
  • 12