Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This line of code is not working for me #1

Open
nagilla-venkatesh opened this issue Aug 4, 2024 · 0 comments
Open

This line of code is not working for me #1

nagilla-venkatesh opened this issue Aug 4, 2024 · 0 comments

Comments

@nagilla-venkatesh
Copy link

https://github.com/sbgowtham/pyspark/blame/6426d2fe52acb0366fa70541e21261b5a71e6c5f/delimiter.py#L16

so I have changed the expression like below:

from pyspark.sql.functions import regexp_replace

df = df.withColumn('value', regexp_replace(col('value'), "[,\t|]", ","))

And one more thing is instead of using df.withColumn multiple times use the below code for readability purpose:

df = df.withColumns({
"id": split_col.getItem(0),
"name": split_col.getItem(1),
"age": split_col.getItem(2),
"city": split_col.getItem(3)
})

withColumns will work from pyspark 3.3+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant