python - 从 Graphlab SFrame 的特定列中查找具有 "Not Applicable"值的行

标签 python dataframe na graphlab sframe

给定一个具有以下列名称的 Graphlab.SFrame 对象:

>>> import graphlab
>>> sf = graphlab.SFrame.read_csv('some.csv')
>>> s.column_names()
['Dataset', 'Domain', 'Score', 'Sent1', 'Sent2']

可以很容易地删除特定列中具有“不适用”(NA)/无值的行,例如要删除“分数”列的具有 NA 值的行,我可以这样做:

>>> sf.dropna('Score')

或者要用某个值(比如 -1)替换 None 值,我可以这样做:

>>> sf.fillna('Score', -1)

检查来自 https://dato.com/products/create/docs/generated/graphlab.SFrame.html 的 SFrame 文档后, 没有内置函数来查找特定列不包含 None 的行,例如 sf.findna('Score')。或者我可能错过了它。

如果有这样的函数,它叫什么?

如果没有,我应该如何提取该行中具有 NA 值的指定列的行?

最佳答案

我认为您可以使用 bool 数组来识别给定列中具有缺失值的行。

>>> import graphlab
>>> sf = graphlab.SFrame({'a': [1, 2, None, 4],
...                       'b': [None, 3, 1, None]})
>>> mask = sf['a'] == None
>>> mask
dtype: int
Rows: 4
[0, 0, 1, 0]

关于python - 从 Graphlab SFrame 的特定列中查找具有 "Not Applicable"值的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34325089/

相关文章:

python - 使用 nginx 将 http 重定向到 https 而不是使用 django-sslify?

Python 3.0 - 如何输出计数最多的字符?

Python:将excel数据转换成dataframes

r - lm : complete cases used even with predictors without missing data 中缺少数据行为

r - 获取向量中缺失值的运行长度

r - 更改级别时如何保持 NA

Python SUDS 错误

python - 如何在Python中仅针对特定数字字符重新格式化字母数字字符串?

python - 检查类型 : How to check if something is a RDD or a DataFrame?

python - 根据另一个列表从 pandas 数据框列中的列表中删除值