我有一个大型的pyspark.sql.dataframe.DataFrame
,我想保留(使用filter
)所有在location
列保存的URL包含预定字符串的行,例如'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'
我如何在DataFrame中进行筛选并正确过滤?
google.com
和amazon.com
,使用like
该怎么做呢?我们应该怎么做? - cph_stodf.filter("location like '%google.com%' AND location like '%amazon.com%'")
,而使用 DataFrame 方式则为df.filter("location like '%google.com%'").filter("location like '%amazon.com%'")
。 - mrsrinivasdf.filter(F.col("yourcol").rlike('|'.join(substrings)))
,其中substrings是一个子字符串列表,如substrings = ['google.com','amazon.com']
。 - anky