欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Pandas按周/月/年統(tǒng)計(jì)數(shù)據(jù)介紹

 更新時(shí)間:2021年12月14日 10:08:00   作者:小旺不正經(jīng)  
大家好,本篇文章主要講的是Pandas按周/月/年統(tǒng)計(jì)數(shù)據(jù)介紹,感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽

Pandas 按周、月、年、統(tǒng)計(jì)數(shù)據(jù)

介紹

將日期轉(zhuǎn)為時(shí)間格式 并設(shè)置為索引

import pandas as pd
data=pd.read_excel('5\TB201812.xls',usecols=['訂單創(chuàng)建時(shí)間','總金額'])
print(data)
data['訂單創(chuàng)建時(shí)間']=pd.to_datetime(data['訂單創(chuàng)建時(shí)間'])
data=data.set_index('訂單創(chuàng)建時(shí)間')
print(data)

image-20211212113513921

按周、月、季度、年統(tǒng)計(jì)數(shù)據(jù)

import pandas as pd
data=pd.read_excel('5\TB201812.xls',usecols=['訂單創(chuàng)建時(shí)間','總金額'])
data['訂單創(chuàng)建時(shí)間']=pd.to_datetime(data['訂單創(chuàng)建時(shí)間'])
data=data.set_index('訂單創(chuàng)建時(shí)間')
print(data.resample('w').sum())
print(data.resample('m').sum())
print(data.resample('Q').sum())
print(data.resample('AS').sum())

image-20211212113905454

image-20211212113915052

使用to_period()方法 優(yōu)化

按月、季度和年顯示數(shù)據(jù)(不統(tǒng)計(jì)數(shù)據(jù))

import pandas as pd
data=pd.read_excel('5\TB201812.xls',usecols=['訂單創(chuàng)建時(shí)間','總金額'])
data['訂單創(chuàng)建時(shí)間']=pd.to_datetime(data['訂單創(chuàng)建時(shí)間'])
data=data.set_index('訂單創(chuàng)建時(shí)間')
print(data.resample('w').sum().to_period('w'))
print(data.resample('m').sum().to_period('m'))
print(data.resample('q').sum().to_period('q'))
print(data.resample('as').sum().to_period('a'))

image-20211212114219970

image-20211212114235410

與之前相比 日期的顯示方式發(fā)生了改變

到此這篇關(guān)于Pandas按周/月/年統(tǒng)計(jì)數(shù)據(jù)介紹的文章就介紹到這了,更多相關(guān)Pandas統(tǒng)計(jì)數(shù)據(jù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論