首页 \ 问答 \ PySpark DataFrame过滤器使用条件列表上的逻辑AND(PySpark DataFrame filter using logical AND over a list of conditions)

PySpark DataFrame过滤器使用条件列表上的逻辑AND(PySpark DataFrame filter using logical AND over a list of conditions)

我正在尝试过滤所有列的值为零的PySpark数据帧的行。

我希望使用这样的东西:

from pyspark.sql.functions import col
df.filter(all([(col(c) != 0) for c in df.columns]))

但我得到一个ValueError:

ValueError: Cannot convert column into bool: please use '&' for 'and', '|' for 'or', '~' for 'not' when building DataFrame boolean expressions.

有没有办法执行逻辑和条件列表?


I'm trying to filter rows of a PySpark dataframe where the values of all columns are zero.

I was hoping to use something like this:

from pyspark.sql.functions import col
df.filter(all([(col(c) != 0) for c in df.columns]))

But I get a ValueError:

ValueError: Cannot convert column into bool: please use '&' for 'and', '|' for 'or', '~' for 'not' when building DataFrame boolean expressions.

Is there any way to perform the logical and on a list of conditions?


原文:https://stackoverflow.com/questions/41239629
更新时间:2023-08-25 17:08

最满意答案

WebCryptographyApi在Android WebView上不受支持,并且webcrypto-shim不针对此组件

该库旨在修复这些具有前缀和错误的webcrypto api实现的浏览器:

Internet Explorer 11,移动Internet Explorer 11,Safari 8及iOS Safari 8及更高版本。

所以你得到了预期的行为。 我认为显示Cordova的window.crypto是旧的实现。

如果您需要密钥存储,我建议使用Android本机密钥库(如果您为其构建,则使用iOS)。 如果您正在寻找加密函数,请包含一个纯JavaScript库


After more research and tests I have found a pure js library that works on cordova.

jsrsasign

I used it to authentificate my JWT. It doesn't use the the crypto.subtle module.

        // Header
        var oHeader = { alg: 'HS256', typ: 'JWT' };
        // Payload
        var oPayload = {};
        var tNow = KJUR.jws.IntDate.get('now');
        var tEnd = KJUR.jws.IntDate.get('now + 1day');
        oPayload.iss = "http://foobar.com";
        oPayload.sub = "mailto:someone@hello.com";
        oPayload.iat = tNow;
        oPayload.exp = tEnd;
        oPayload.jti = "id123";
        oPayload.aud = "http://someUrl";
        oPayload.email = "userEmail";
        oPayload.pwd = "userPassword";
        oPayload.deviceId = "deviceId";

        // Sign JWT.
        var sHeader = JSON.stringify(oHeader);
        var sPayload = JSON.stringify(oPayload);
        //secret -> your secret that the server gave you.
        var sJWT = KJUR.jws.JWS.sign("HS256", sHeader, sPayload, secret);
        console.log(sJWT);

So that's it. It solved my problem.
I know that the undefined crypto.subtle error still exists. I did not find any solutions to that problem.
I supose that one day the developers in charge of cordova will make the effort to support the cryto module that we can find in all other browser but for now the only solution is to used third party libraries.

相关问答

更多
  • WebCrypto函数返回Promises。 它们不是同步的。 结果在回调中收到。 看到这个完整的例子 window.crypto.subtle.generateKey( { name: "AES-CBC", length: 128 }, false, ["encrypt", "decrypt"] ) .then(function(key){ var iv = window.crypto.getRandomValues(new Uint8Array(16)) window.crypto. ...
  • 您的代码尝试查找cust100操作的原因是您的URL正在与默认路由相匹配: routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", i ...
  • 按日期排序,然后查找差距。 start <- as.Date("2014-01-01") time <- as.Date(c("2014-01-06", "2014-01-07","2014-01-09")) end <- as.Date("2014-01-10") time <- sort(unique(time)) # Include start and end dates, so the missing dates are 1/1-1/5, 1/8, 1/10 d <- c(time[1]- st ...
  • IE11或Android(如果您的意思是WebView)不支持Web Cryptography API,但它可以在Android浏览器和Chrome for Android中使用 请参阅http://caniuse.com/cryptography/embed Webcrypto-shim旨在使用部分或非标准实现(如IE11和Safari8)修复旧版浏览器,但是您不会为旧浏览器找到完整的polifyll,因为需要本机实现部分,至少是密钥存储 要加密客户端sid中的数据,你可以使用另一个javascript库 ...
  • 在Chrome 60中,他们添加了一项功能,可以禁用非TLS连接的crypto.subtle 不完全是,自第一个支持的版本(chrome 32?)以来,对于非安全来源, crypto.subtle被禁用 但localhost被认为是安全的来源https://www.chromium.org/Home/chromium-security/prefer-secure-origins-for-powerful-new-features “安全起源”是至少与以下(方案,主机,端口)模式之一匹配的起源: (https ...
  • 假设您的标签('c','cg','rx')位于名为tags_match的表中,其结构与上述相同 然后你可以这样做: select tr.name from tags as tl right join tags_match as tr on tl.name = tr.name where tl.name is null 这将找到tags_match中不在标签中的所有项目,因此这将为您提供所需的结果,但不幸的是您的标签('c','cg','rx')不在表中:( 无论我们可以使用子查询来“ ...
  • 您的代码中有一个小错误。 与crypto无关,只是承诺。 .then()在调用.then()方法时不会更新状态,而是返回新的promise。 在代码中看到,您正在通过调用密钥派生函数来丢弃最终的承诺。 然后,在加密数据时,您将重用密码承诺,而不是密钥。 您应该从新变量中的密钥派生中保存生成的承诺: let promise_derived_key = promise_key.then(function(importedPassword) { return window.crypto.subtle.de ...
  • 几种选择: One Shot(截至Rails 3.2.13): Fixture.where(home_team: home_team, away_team: away_team, fixture_date: date, kickoff_time: kick_off).first_or_create! Several choices: One Shot (as of Rails 3.2.13): Fixture.where(home_team: home_team, away_team: away_team ...
  • WebCryptographyApi在Android WebView上不受支持,并且webcrypto-shim不针对此组件 该库旨在修复这些具有前缀和错误的webcrypto api实现的浏览器: Internet Explorer 11,移动Internet Explorer 11,Safari 8及iOS Safari 8及更高版本。 所以你得到了预期的行为。 我认为显示Cordova的window.crypto是旧的实现。 如果您需要密钥存储,我建议使用Android本机密钥库(如果您为其构建,则使 ...
  • 我解决了自己的问题: 我定义的第二个类是问题,因为它使用另一个根窗口,别名Tk()。等同于普通的Tk()窗口的是Toplevel(),它与根相同但没有自己的解释器上下文。 很快,为了解决这个问题,我不得不改变EditorWindow类的init ()方法的fisrt行 self.Eenu=Tk() 至 self.Eenu=Toplevel() I solved myself the problem : the second class i defined was the ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)