Force pyspark to write string data type to CSV

Viewed 29

While writing a pyspark dataframe to csv, it is converting a column which has numerical values but are represented in form of string because of preceding zeroes for eg: 00,01 and so on.. But while writing it to csv these values become 0,1 and so on.. How can I prevent this?

Current code to csv:

Using jupyter notebook:

%%time
data.write.mode(“overwrite”).csv(“path to file”, header= True)

And

data.printSchema()

Gives output as: col_name: string (nullable= true)

The data is fetched using sql queries

0 Answers
Related