11-23-2022 09:41 AM
hello everyone, I'm creating a regex expression to fetch only the value of a string, but some values are negative. I am not able to create the rule to compose the negative value. can you help me?
from pyspark.sql.functions import regexp_extract
from pyspark.sql.types import StructType,StructField, StringType
data = [("01","[$R$-pt-BR] 150.00"),
("02", "-[$R$-pt-BR] 379.52" ),
("03", "[$R$-pt-BR] 185.16" ),
("04", "[$R$-pt-BR] 185.16" ),]
schema = StructType([ \
StructField("id",StringType(),True), \
StructField("description",StringType(),True),
])
df = spark.createDataFrame(data=data,schema=schema)
df.display()
df1 = df\
.withColumn("value", regexp_extract('description', r"[\d]{1,4}.[\d]{1,4}", 0))
df1.display()
11-24-2022 12:59 AM
Hi there,
Hope it fit your requirement. 🙂
11-23-2022 10:50 AM
@Werner Stinckens
can you help me?
11-24-2022 12:59 AM
Hi there,
Hope it fit your requirement. 🙂
11-24-2022 05:46 AM
11-24-2022 04:26 AM
11-24-2022 07:36 AM
\s*\[[^)]*\] removes the square brackets and everything inside it and the space too (well actually substitutes it with nothing).
https://regex101.com/r/tv9pbJ/1
Haven't checked if spark can do regex substitution.
12-01-2022 03:25 AM
its like you need to find this pattern : "^[\-]?"
03-16-2023 05:50 AM
Have you found the answer? If you are a student in college or school searching for free essay examples online, you may want to visit the website https://writinguniverse.com/free-essay-examples/soccer/ here you will find a vast collection of free essay examples related to various topics, including soccer. These essay examples can be valuable resources to help you complete your essay assignments.
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.
If there isn’t a group near you, start one and help create a community that brings people together.
Request a New Group