《Python數據分析與挖掘實戰》第三章書中代碼
p = data.boxplot() #畫箱線圖,直接使用DataFrame的方法
x = p['fliers'][0].get_xdata() # 'flies'即為異常值的標簽
y = p['fliers'][0].get_ydata()
報錯:
x = p['fliers'][0].get_xdata()
TypeError: 'AxesSubplot' object is not subscriptable
查看pandas文檔貼上原文和中文翻譯
return_type : {‘axes’, ‘dict’, ‘both’} or None, default ‘axes’ The
kind of object to return. The default is axes.‘axes’ returns the matplotlib axes the boxplot is drawn on.
‘dict’ returns a dictionary whose values are the matplotlib Lines of
the boxplot.‘both’ returns a namedtuple with the axes and dict.
return_type : {‘axes’,‘dict’,‘both’}或None,默認’axes’
要返回的那種對象。默認是axes。
'axes’返回繪制boxplot的matplotlib軸。
'dict’返回一個字典,其值是boxplot的matplotlib行。
'both’返回一個帶有軸和dict的namedtuple。
將三個參數都試一遍
-
return_type=‘axes’,返回的是
AxesSubplot(0.125,0.11;0.775x0.77)
,應該就是箱圖的軸對象 - return_type=“dict”,返回的是
{'whiskers': [
,
],
'caps': [
,
],
'boxes': [
],
'medians': [
],
'fliers': [
],
'means': []}
字典里面就是組成箱圖的各個元素,其中
fliers
表示離散點,通過
p['fliers'][0]
獲取點坐標
- return_type=“both”,返回的就是兩者結合
Boxplot(ax=
,
lines={'whiskers': [
,
],
'caps': [
,
],
'boxes': [
],
'medians': [
],
'fliers': [
],
'means': []})
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
