generate time series dataframe based on a given dataframe [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



generate time series dataframe based on a given dataframe [duplicate]



This question already has an answer here:



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


time


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


Time


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.



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





df.groupby('Time').bill.sum()
– Wen
Aug 13 at 2:42




1 Answer
1


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

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard