python 数据分析学习笔记 (第三章)
生活随笔
收集整理的這篇文章主要介紹了
python 数据分析学习笔记 (第三章)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
百度云代碼連接:http://pan.baidu.com/s/1hr4QGgG 密碼:puxw
boxplot 箱形圖
catering_sale = '../data/catering_sale.xls' #餐飲數(shù)據(jù) data = pd.read_excel(catering_sale) #讀取數(shù)據(jù),指定“日期”列為索引列import matplotlib.pyplot as plt #導(dǎo)入圖像庫plt.rcParams['font.sans-serif'] = ['SimHei'] #用來正常顯示中文標(biāo)簽 plt.rcParams['axes.unicode_minus'] = False #用來正常顯示負號plt.figure() #建立圖像 p = data.boxplot(return_type='dict') #畫箱線圖,直接使用DataFrame的方法 x = p['fliers'][0].get_xdata() # 'flies'即為異常值的標(biāo)簽 y = p['fliers'][0].get_ydata() y.sort() #從小到大排序,該方法直接改變原對象#用annotate添加注釋 #其中有些相近的點,注解會出現(xiàn)重疊,難以看清,需要一些技巧來控制。 #以下參數(shù)都是經(jīng)過調(diào)試的,需要具體問題具體調(diào)試。 for i in range(len(x)): if i>0:plt.annotate(y[i], xy = (x[i],y[i]), xytext=(x[i]+0.05 -0.8/(y[i]-y[i-1]),y[i]))else:plt.annotate(y[i], xy = (x[i],y[i]), xytext=(x[i]+0.08,y[i]))plt.show() #展示箱線圖統(tǒng)計量分析
from __future__ import print_function import pandas as pdcatering_sale = '../data/catering_sale.xls' #餐飲數(shù)據(jù) data = pd.read_excel(catering_sale) #讀取數(shù)據(jù),指定“日期”列為索引列 data = data[(data[u'銷量'] > 400)&(data[u'銷量'] < 5000)] #過濾異常數(shù)據(jù) statistics = data.describe() #保存基本統(tǒng)計量statistics.loc['range'] = statistics.loc['max']-statistics.loc['min'] #極差 statistics.loc['var'] = statistics.loc['std']/statistics.loc['mean'] #變異系數(shù) statistics.loc['dis'] = statistics.loc['75%']-statistics.loc['25%'] #四分位數(shù)間距print(statistics)帕累托圖
dish_profit = '../data/catering_dish_profit.xls' #餐飲菜品盈利數(shù)據(jù) data = pd.read_excel(dish_profit) data = data[u'盈利'].copy() data.sort(ascending = False)import matplotlib.pyplot as plt #導(dǎo)入圖像庫 plt.rcParams['font.sans-serif'] = ['SimHei'] #用來正常顯示中文標(biāo)簽 plt.rcParams['axes.unicode_minus'] = False #用來正常顯示負號plt.figure() data.plot(kind='bar') plt.ylabel(u'盈利(元)') p = 1.0*data.cumsum()/data.sum() p.plot(color = 'r', secondary_y = True, style = '-o',linewidth = 2) plt.annotate(format(p[6], '.4%'), xy = (6, p[6]), xytext=(6*0.9, p[6]*0.9), arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2")) #添加注釋,即85%處的標(biāo)記。這里包括了指定箭頭樣式。 plt.ylabel(u'盈利(比例)') plt.show()相關(guān)系數(shù)的 d.corr()
from __future__ import print_function import pandas as pdcatering_sale = '../data/catering_sale_all.xls' #餐飲數(shù)據(jù),含有其他屬性 data = pd.read_excel(catering_sale) #讀取數(shù)據(jù),指定“日期”列為索引列data.corr() #相關(guān)系數(shù)矩陣,即給出了任意兩款菜式之間的相關(guān)系數(shù) data.corr()[u'百合醬蒸鳳爪'] #只顯示“百合醬蒸鳳爪”與其他菜式的相關(guān)系數(shù) data[u'百合醬蒸鳳爪'].corr(data[u'翡翠蒸香茜餃']) #計算“百合醬蒸鳳爪”與“翡翠蒸香茜餃”的相關(guān)系數(shù)d.describe()
import pandas as pd cc='../data/catering_sale.xls' data=pd.read_excel(cc) data.describe()總結(jié)
以上是生活随笔為你收集整理的python 数据分析学习笔记 (第三章)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pie hist plot boxpl
- 下一篇: DataFrame 学习笔记