In order to remove leading zero of column in pyspark, we use regexp_replace() function and we remove consecutive leading zeros. Lets see an example on how to remove leading zeros of the column in pyspark.
- Remove Leading Zero of column in pyspark
We will be using dataframe df.
Remove leading zero of column in pyspark
We use regexp_replace() function with column name and regular expression as argument and thereby we remove consecutive leading zeros.
### Remove leading zero of column in pyspark from pyspark.sql.functions import * import pyspark.sql.functions as F df = df.withColumn('grad_Score_new', F.regexp_replace('grad_Score', r'^*', ''))
so the resultant dataframe with leading zeros removed will be