Filtering DataFrame using the length of a column

前端 未结 3 1436
耶瑟儿~
耶瑟儿~ 2020-12-02 22:28

I want to filter a DataFrame using a condition related to the length of a column, this question might be very easy but I didn\'t find any related question in th

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-02 22:52

    Here is an example for String in scala:

    val stringData = Seq(("Maheswara"), ("Mokshith"))
    val df = sc.parallelize(stringData).toDF
    df.where((length($"value")) <= 8).show
    +--------+
    |   value|
    +--------+
    |Mokshith|
    +--------+
    df.withColumn("length", length($"value")).show
    +---------+------+
    |    value|length|
    +---------+------+
    |Maheswara|     9|
    | Mokshith|     8|
    +---------+------+
    

提交回复
热议问题