0

I have a dataframe with a datetime column, I am trying to get the print out of the sum of all the values with the same datetime and then do an average afterwards of all the values. Here is what I have:

df[col] = pd.to_datetime(df[col]).dt.date
df.groupby([col]).sum()

But I just get a print out of all the dates and not their associated values with how often they appear

Date_Recieved
2017-01-01
2017-01-02
2017-01-03
2017-01-04
2017-01-05

After this I was hoping to save all the values and do a single average

wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • I can't reproduce the issue. Are you sure you're working on the right df? Cause it looks like it simply only has that one column. Otherwise, you need to provide a [mre]. For specifics, see [How to make good reproducible pandas examples](/q/20109391/4518341). If you want more tips, see [ask]. – wjandrea Jun 04 '22 at 01:43
  • @wjandrea does groupby have to have more than one column? I was trying to see how many rows are corresponding to that one column for each date so that is the only column in my dataframe – Arica Christensen Jun 04 '22 at 01:46
  • 1
    Oh, I see! You don't want a sum, you want a count. There's an existing question about that: [Count the frequency that a value occurs in a dataframe column](/q/22391433/4518341). Use `df[col].value_counts()`. – wjandrea Jun 04 '22 at 01:56

0 Answers0