【发布时间】:2016-02-15 04:34:52
【问题描述】:
我想使用与列长度相关的条件过滤DataFrame,这个问题可能很简单,但我在 SO 中没有找到任何相关问题。
更具体地说,我有一个DataFrame,只有一个ColumnArrayType(StringType()),我想使用长度作为过滤器过滤DataFrame,我在下面拍摄了一个sn-p。
df = sqlContext.read.parquet("letters.parquet")
df.show()
# The output will be
# +------------+
# | tokens|
# +------------+
# |[L, S, Y, S]|
# |[L, V, I, S]|
# |[I, A, N, A]|
# |[I, L, S, A]|
# |[E, N, N, Y]|
# |[E, I, M, A]|
# |[O, A, N, A]|
# | [S, U, S]|
# +------------+
# But I want only the entries with length 3 or less
fdf = df.filter(len(df.tokens) <= 3)
fdf.show() # But it says that the TypeError: object of type 'Column' has no len(), so the previous statement is obviously incorrect.
我阅读了Column's Documentation,但没有发现任何对此事有用的属性。我很感激任何帮助!
【问题讨论】:
标签: python apache-spark dataframe pyspark apache-spark-sql