Pandas statistics by week, month, year, stats
present (sb for a job etc)
Convert date to time format and set as an index
import pandas as pd data=pd.read_excel('5\',usecols=['Order creation time','Total amount']) print(data) data['Order creation time']=pd.to_datetime(data['Order creation time']) data=data.set_index('Order creation time') print(data)
Statistics by week, month, quarter, year
import pandas as pd data=pd.read_excel('5\',usecols=['Order creation time','Total amount']) data['Order creation time']=pd.to_datetime(data['Order creation time']) data=data.set_index('Order creation time') print(('w').sum()) print(('m').sum()) print(('Q').sum()) print(('AS').sum())
Using the to_period() method Optimization
Display of data by month, quarter and year (no statistics)
import pandas as pd data=pd.read_excel('5\',usecols=['Order creation time','Total amount']) data['Order creation time']=pd.to_datetime(data['Order creation time']) data=data.set_index('Order creation time') print(('w').sum().to_period('w')) print(('m').sum().to_period('m')) print(('q').sum().to_period('q')) print(('as').sum().to_period('a'))
The way dates are displayed has changed compared to the previous one.
This article on Pandas weekly/monthly/yearly statistics is introduced to this article, more related Pandas statistics content please search my previous posts or continue to browse the following related articles I hope you will support me in the future!