0

There is a dataframe, which includes one column of time and another column of bill. As can be seen from the table, there can have multiple records for a single day. The order of time can be random

time                              bill
2006-1-18                          10.11
2006-1-18                          9.02
2006-1-19                          12.34
2006-1-20                          6.86
2006-1-12                          10.05

Based on these information, I would like to generate a time series dataframe, which has two columns Time and total bill

The time column will save the date in order, the total bill will save the sum of multiple bill records belonging to one day.

user297850
  • 7,705
  • 17
  • 54
  • 76

1 Answers1

0
newdf = pd.DataFrame(df.groupby('time').bill.sum())
newdf.rename(columns={'time':'Time', 'bill': 'total bill'}, inplace = True)
newdf

output:

    Time    total_bill
0   2006-1-18   10.11
1   2006-1-18   9.02
2   2006-1-19   12.34
3   2006-1-20   6.86
4   2006-1-12   10.05
pwxcoo
  • 2,903
  • 2
  • 15
  • 21