Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

find the count of each date in dataframe

I need to group the columns according to the date.

enter image description here

starttime   Dates   COUNT
0   2019-09-01 00:00:01.9580    2019-09-01  0
1   2019-09-01 00:00:04.1430    2019-09-01  0
2   2019-09-01 00:00:07.3090    2019-09-01  0
3   2019-09-01 00:00:08.0640    2019-09-01  0
4   2019-09-01 00:00:12.8510    2019-09-01  0
... ... ... ...
195 2019-09-01 00:08:17.9740    2019-09-01  0
196 2019-09-01 00:08:23.9270    2019-09-01  0
197 2019-09-01 00:08:25.5040    2019-09-01  0
198 2019-09-01 00:08:26.2810    2019-09-01  0
199 2019-09-01 00:08:27.3220    2019-09-01  0

I have used the below to split my ‘starttime’ column to just the Date and Time. I want to count the number of occurences of each date in ‘COUNT column.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

df['Dates'] = pd.to_datetime(df['starttime']).dt.date
df['Time'] = pd.to_datetime(df['starttime']).dt.time

For example

Date       COUNT
2019-09-01    25
2019-09-02    34

How can i do this?

>Solution :

Try this :

output = df.Dates.value_counts().reset_index()
output.columns = ["Date", "Count"]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading