graphlab create sframe 如何获取 SArray 中位数

graphlab create sframe how to get SArray median

我正在学习 graphlab create

data=graphlab.SFrame.read_csv('test.csv')

我正在尝试获取其中一列的中位数

data_train.fillna(('Credit_History',data_train['Credit_History'].median()))

但是我得到了错误

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-247-50ed3eb09dcc> in <module>()
----> 1 data_train.fillna(('Credit_History',data_train['Credit_History'].median()))

AttributeError: 'SArray' object has no attribute 'median'

data.show() 将显示此列的中位数 任何人都知道如何解决这个问题?

SArray 没有中位数方法。获得中位数的最佳方法是通过 sketch_summary 方法,然后是 quantile。有关草图摘要的更多信息,请访问

https://turi.com/products/create/docs/generated/graphlab.Sketch.html

import numpy as np
import graphlab as gl

sf = gl.SFrame(np.random.rand(100))

sketch = sf['X1'].sketch_summary()
median = sketch.quantile(0.5)

我想我明白你想做什么。 Sframe 没有默认的中值函数。我会这样即兴发挥:

import numpy as np
data_train.fillna('Credit_History', np.median(data_train['Credit_History']))