3

I have a column in my table which have this value :

  |col_A|
  -------
  |00140|
  -------
  |00120|
  -------
  |00058|
  -------
  |00009|
  -------
  |00052|

I want to delete all 0 in the left. I use pyspark to build the dataframe. You find as below an exemple :

while tab.col_A.like('0%'):
        tab = tab.withColumn('tab_B', tab['col_A'][2:5])

When I try to execute this code I have this error :

Cannot convert column into bool

Please help.

1 Answer 1

3

I tried this code :

tab = tab.withColumn("col_B", F.regexp_extract(tab['col_A'], '[1-9][0-9]*',0))

The problem is resolved.

Thanks,

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.