我有一个很大的 pyspark.sql.dataframe.DataFrame
,我想保留(所以 filter
)URL 保存在 location< 中的所有行
列包含一个预先确定的字符串,例如'google.com'。
我试过了:
import pyspark.sql.functions as sf
df.filter(sf.col('location').contains('google.com')).show(5)
但这会引发
TypeError: _TypeError: 'Column' object is not callable'
如何正确过滤我的 df?提前谢谢了!
最佳答案
Spark 2.2 以后
df.filter(df.location.contains('google.com'))
Spark 2.1 及之前的版本
You can use plain SQL in
filter
df.filter("location like '%google.com%'")
or with DataFrame column methods
df.filter(df.location.like('%google.com%'))
关于python - 当值与pyspark中字符串的一部分匹配时过滤df,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41889974/