Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

This seems like it would be fairly straight forward but after nearly an entire day I have not found the solution. I've loaded my dataframe with read_csv and easily parsed, combined and indexed a date and a time column into one column but now I want to be able to just reshape and perform calculations based on hour and minute groupings similar to what you can do in excel pivot.

I know how to resample to hour or minute but it maintains the date portion associated with each hour/minute whereas I want to aggregate the data set ONLY to hour and minute similar to grouping in excel pivots and selecting "hour" and "minute" but not selecting anything else.

Any help would be greatly appreciated.

1 Answer

0 votes
by (41.4k points)

Use these below line of code where df is your DataFrame:

times = pd.to_datetime(df.timestamp_col)

df.groupby([times.hour, times.minute]).value_col.sum()

If You want to learn data science with python visit this data science online course by intellipaat.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...