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.

Connect with Databricks Users in Your Area

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