Oharra
Baimena behar duzu orria atzitzeko. Direktorioetan saioa has dezakezu edo haiek alda ditzakezu.
Baimena behar duzu orria atzitzeko. Direktorioak alda ditzakezu.
Filtra las filas mediante la condición especificada.
Sintaxis
filter(condition: Union[Column, str])
Parámetros
| Parámetro | Tipo | Descripción |
|---|---|---|
condition |
Columna o str | Columna de BooleanType o una cadena de expresiones SQL. |
Devoluciones
DataFrame: un nuevo DataFrame con filas que cumplen la condición.
Ejemplos
df = spark.createDataFrame([
(2, "Alice", "Math"), (5, "Bob", "Physics"), (7, "Charlie", "Chemistry")],
schema=["age", "name", "subject"])
df.filter(df.age > 3).show()
# +---+-------+---------+
# |age| name| subject|
# +---+-------+---------+
# | 5| Bob| Physics|
# | 7|Charlie|Chemistry|
# +---+-------+---------+
df.where(df.age == 2).show()
# +---+-----+-------+
# |age| name|subject|
# +---+-----+-------+
# | 2|Alice| Math|
# +---+-----+-------+
df.filter("age > 3").show()
# +---+-------+---------+
# |age| name| subject|
# +---+-------+---------+
# | 5| Bob| Physics|
# | 7|Charlie|Chemistry|
# +---+-------+---------+
df.filter((df.age > 3) & (df.subject == "Physics")).show()
# +---+----+-------+
# |age|name|subject|
# +---+----+-------+
# | 5| Bob|Physics|
# +---+----+-------+