【问题标题】:Using like operator to filter columns names in scala使用like运算符过滤scala中的列名
【发布时间】:2020-01-28 23:37:18
【问题描述】:

我有一个数据框,我想从中创建一个所有以某个短语开头并以某个其他短语结尾的列的列表。

请帮我写一下语句,目前我用的是startswith和endswith,分别正确,但是用AND条件就不行了。

请帮我编写 SCALA 代码。

下面是我要执行的行

  val list_inactive_w  = usg.columns.filter(_.startsWith("max_consecut") AND (_.endsWith("ays_data_w")))

【问题讨论】:

    标签: python scala dataframe apache-spark pyspark


    【解决方案1】:
    val list_inactive_w  = usg.columns.filter(s=>s.startsWith("max_consecut") && s.endsWith("ays_data_w"))
    

    【讨论】:

    • 谢谢 - 这很有效,请告诉我这个 S 在这个声明中做了什么?
    • "S" 只是像 _ 一样的参数,这种情况下 _ 只能使用一次,"s" 可以多次使用,这个 "s" 只是一个名字,可以不同
    • 感谢所有帮助。我已经在 python 中编写了一个代码,并在 python 中获取了具有字符串类型的数据帧的所有列,现在我想在 scala 中做同样的事情。我是 scala 的新手,你能帮忙吗?下面是代码。 val cons_Day3= [t[0] for t in df2 if t[1] == 'string']
    • 你可以这样检查类型:df.schema.foreach(x=>print(x.dataType))
    猜你喜欢
    • 2021-08-24
    • 2021-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多