python - summing the number of occurrences per day pandas -


i have data set in pandas dataframe.

                                  score timestamp                                  2013-06-29 00:52:28+00:00        -0.420070 2013-06-29 00:51:53+00:00        -0.445720 2013-06-28 16:40:43+00:00         0.508161 2013-06-28 15:10:30+00:00         0.921474 2013-06-28 15:10:17+00:00         0.876710 

i need counts number of measurements, occur looking this

                                    count    timestamp    2013-06-29                       2    2013-06-28                       3 

i dont not care sentiment column want count of occurrences per day.

if timestamp index datetimeindex:

import io import pandas pd content = '''\ timestamp  score 2013-06-29 00:52:28+00:00        -0.420070 2013-06-29 00:51:53+00:00        -0.445720 2013-06-28 16:40:43+00:00         0.508161 2013-06-28 15:10:30+00:00         0.921474 2013-06-28 15:10:17+00:00         0.876710 '''  df = pd.read_table(io.bytesio(content), sep='\s{2,}', parse_dates=[0], index_col=[0])  print(df) 

so df looks this:

                        score timestamp                     2013-06-29 00:52:28 -0.420070 2013-06-29 00:51:53 -0.445720 2013-06-28 16:40:43  0.508161 2013-06-28 15:10:30  0.921474 2013-06-28 15:10:17  0.876710  print(df.index) # <class 'pandas.tseries.index.datetimeindex'> 

you can use:

print(df.groupby(df.index.date).count()) 

which yields

            score 2013-06-28      3 2013-06-29      2 

note importance of parse_dates parameter. without it, index pandas.core.index.index object. in case not use df.index.date.

so answer depends on type(df.index), have not shown...


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -