Welcome to Kontext!

Start sharing your knowledge today with Kontext Column.

The platform that makes publishing awesome content easy and free.

article Article

Write articles, blog posts, and other content effortlessly with Markdown and HTML editor.

Markdown editor

image Diagram

Visualize your ideas with stunning BPMN, UML, and cloud solution diagrams.

Diagrams

code Code

Share your code snippets and connect with a community of like-minded developers.

Code snippets

from pyspark.sql import SparkSession
from pyspark.sql.functions import regexp_replace

app_name = "PySpark regex_replace Example"
master = "local"

spark = SparkSession.builder \
    .appName(app_name) \
    .master(master) \
    .getOrCreate()

spark.sparkContext.setLogLevel("WARN")

data = [[1, 'ABCDEDF!@#$%%^123456qwerty'],
        [2, 'ABCDE!!!']
        ]

df = spark.createDataFrame(data, ['id', 'str'])

df.show(truncate=False)

df = df.select("id", regexp_replace("str", "[^0-9a-zA-Z_\-]+", ""
                                    ).alias('replaced_str'))

df.show()
Loading...

insights Insights

Monitor your articles' performance, track views, and learn what resonates with your audience.

Featured content

rss_feed