Chcę filtrować DataFrame
przy użyciu warunku związanego z długością kolumny, to pytanie może być bardzo proste, ale nie znalazłem żadnego powiązanego pytania w SO.Filtrowanie DataFrame przy użyciu długości kolumny
dokładniej, mam DataFrame
tylko jeden Column
które z ArrayType(StringType())
chcę filtrować DataFrame
pomocą długość jak filterer, kręciłem fragment poniżej.
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 czytałem, ale nie znaleźliśmy żadnego majątku przydatna dla sprawy. Doceniam każdą pomoc!
Co jeśli kolumna jest 'string' i udaję filtrować według długości' string' za? –
Ta sama funkcja udf lub 'length'. – zero323