我有一个带有Spark1.6的python DataFrame。例如
DF= ("timestamp","canal", "name")示例数据:
[('1980-02-24'),('google.com/General'),('Alice')]
[('1980-02-24'),('google.com/Dataset'),('bob')]
[('1980-02-24'),('googleserach.com'),('Malik')]
[('1980-02-24'),('googlesearch.com/AIPlateforme'),('AliceBob')]
[('1980-02-24'),('yahooserach.com'),('Bob2')]
[('1980-02-24'),('yahoosearch.com/AIPlateforme'),('Alice2')]
DF.count() = 6我想要所有的代码,"canal" not contain substring googleserach.com not contain yahoosearch
我创建了一个变量:
canal_2 = "googleserach.com,yahoosearch"然后:
解决方案1:
result = DF.filter(~DF.canal.isin (canal_2)) ==> does not work
result.count() = 6解决方案2:
if (canal2 not in DF.canal) ==> invalid syntax我如何在我的DataFrame上进行过滤,以获取"canal“中不包含googlesearch和yahoosearch的行?
谢谢
发布于 2018-11-07 03:47:15
rlike和regex将会正常工作。
regexNegativeLB= "^/(?!googlesearch|yahoosearch)$"
newDF= DF.filter(DF["canal"].rlike(regexNegativeLB))发布于 2018-11-07 04:10:11
df = spark.createDataFrame([
('1980-02-24','google.com/General','Alice'),
('1980-02-24','google.com/Dataset','bob'),
('1980-02-24','googleserach.com','Malik'),
('1980-02-24','googlesearch.com/AIPlateforme','AliceBob'),
('1980-02-24','yahooserach.com','Bob2'),
('1980-02-24','yahoosearch.com/AIPlateforme','Alice2')
], schema=("dt","canal","name"))
df.filter(~df.canal.like('%google.com%') & ~df.canal.like('%yahoosearch%')).show()也有可能。pyspark没有包含它的出现。
发布于 2018-11-07 12:59:54
df.filter(~df"canal".isin(canal_2)).collect()试试这个。
https://stackoverflow.com/questions/53178705
复制相似问题