using Python, How to group a column in Dataframe by the hour?

Vijay

I have a python dataframe (df1) which has a column time. I converted the column into a datetime series using pd.to_datetime(df1['time']). Now I get a column like this:

2016-08-24 00:00:00  2016-08-13  00:00:00   
2016-08-24 00:00:00  2016-08-13  00:00:00     
2016-08-24 00:00:00  2016-08-13  00:00:00   
2016-08-24 00:00:00  2016-08-13  00:00:00  
2016-08-24 00:00:01  2016-08-13  00:00:01   
2016-08-24 00:00:01  2016-08-13  00:00:01   
2016-08-24 00:00:02  2016-08-13  00:00:02  
2016-08-24 00:00:02  2016-08-13  00:00:02     
2016-08-24 00:00:02  2016-08-13  00:00:02    
2016-08-24 00:00:02  2016-08-13  00:00:02     
2016-08-24 00:00:02  2016-08-13  00:00:02     
2016-08-24 00:00:02  2016-08-13  00:00:02     
2016-08-24 00:00:02  2016-08-13  00:00:02    
2016-08-24 00:00:02  2016-08-13  00:00:02    
2016-08-24 00:00:02  2016-08-13  00:00:02     
....

2016-08-24 23:59:59  2016-08-13  00:00:02  

Essentially, I want the first column to be grouped by the hour, so that I can see how many entries are there in 1 hour. Any help will be great.

Merlin

Using @jezrael setup.

df.resample(rule='H', how='count').rename(columns = {'time':'count'})

                      count
2016-08-24 00:00:00      1
2016-08-24 01:00:00      3
2016-08-24 02:00:00      1

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Truncate `TimeStamp` column to hour precision in pandas `DataFrame`

From Dev

How to group HKStatistics by hour?

From Dev

Add a group column to a dataframe

From Dev

how to group by one column only using linq?

From Dev

How to group a dataframe by some transform of a column

From Dev

How to group a DataFrame using labels and sum them?

From Dev

how to add hour to pandas dataframe column

From Dev

Rails group by hour of the day for created_at column

From Dev

How to check whether the content of Column A is contained in Column B using Python DataFrame?

From Dev

How to lemmatise a dataframe column Python

From Dev

How to extract and increment the hour from text (str) using Python

From Dev

How to group HKStatistics by hour?

From Dev

how to group by one column only using linq?

From Dev

How to group a dataframe by some transform of a column

From Dev

Creating a new column in panda dataframe using logical indexing and group by

From Dev

Rails group by hour of the day for created_at column

From Dev

How to check whether the content of Column A is contained in Column B using Python DataFrame?

From Dev

How to extract hour part of timestamp to a new column in DataFrame Spark

From Dev

Dataframe column showing half hour intervals

From Dev

How to group a column in a csv file by a range and plot histogram using python?

From Dev

How to Sum column using group by in mysql?

From Dev

Dataframe: group with an discontinuous column

From Dev

Group by hour using Oracle SQL

From Dev

How to count words and group by hour?

From Dev

How do I "enrich" every record in a Pandas dataframe with an hour column?

From Dev

Find the increase, decrease in column of Dataframe group by an other column in Python / Pandas

From Dev

Transpose column and group dataframe

From Dev

how to remove a column from Pandas dataframe using Python?

From Dev

How to group DataFrame values by hour?

Related Related

  1. 1

    Truncate `TimeStamp` column to hour precision in pandas `DataFrame`

  2. 2

    How to group HKStatistics by hour?

  3. 3

    Add a group column to a dataframe

  4. 4

    how to group by one column only using linq?

  5. 5

    How to group a dataframe by some transform of a column

  6. 6

    How to group a DataFrame using labels and sum them?

  7. 7

    how to add hour to pandas dataframe column

  8. 8

    Rails group by hour of the day for created_at column

  9. 9

    How to check whether the content of Column A is contained in Column B using Python DataFrame?

  10. 10

    How to lemmatise a dataframe column Python

  11. 11

    How to extract and increment the hour from text (str) using Python

  12. 12

    How to group HKStatistics by hour?

  13. 13

    how to group by one column only using linq?

  14. 14

    How to group a dataframe by some transform of a column

  15. 15

    Creating a new column in panda dataframe using logical indexing and group by

  16. 16

    Rails group by hour of the day for created_at column

  17. 17

    How to check whether the content of Column A is contained in Column B using Python DataFrame?

  18. 18

    How to extract hour part of timestamp to a new column in DataFrame Spark

  19. 19

    Dataframe column showing half hour intervals

  20. 20

    How to group a column in a csv file by a range and plot histogram using python?

  21. 21

    How to Sum column using group by in mysql?

  22. 22

    Dataframe: group with an discontinuous column

  23. 23

    Group by hour using Oracle SQL

  24. 24

    How to count words and group by hour?

  25. 25

    How do I "enrich" every record in a Pandas dataframe with an hour column?

  26. 26

    Find the increase, decrease in column of Dataframe group by an other column in Python / Pandas

  27. 27

    Transpose column and group dataframe

  28. 28

    how to remove a column from Pandas dataframe using Python?

  29. 29

    How to group DataFrame values by hour?

HotTag

Archive