cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Infer schema eliminating leading zeros.

AnkithP
New Contributor

Upon reading a CSV file with schema inference enabled, I've noticed that a column originally designated as string datatype contains numeric values with leading zeros. However, upon reading the data to Pyspark data frame, it undergoes automatic conversion to integers, resulting in the removal of the leading zeros.

How can I resolve this issue without passing the external schema while reading.

1 REPLY 1

-werners-
Esteemed Contributor III

if you set .option("inferSchema", "false") all columns will be read as string.
You will have to cast all the other columns to their appropriate type though.  So passing a schema seems easier to me.

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!