Create delta table using csv file

Viewed 1993

I'm trying to create delta table in databricks. I'm using this link as a referrence for learning.Here it's mentioned that For all file types, I need to read the files into a DataFrame and write out in delta format:. So I wrote following code in python

import pandas as pd
df=pd.read_csv('my file path/data.csv')
df.write.format("delta").save("/mnt/delta/df")
spark.sql("CREATE TABLE df USING DELTA LOCATION '/mnt/delta/df/'")

But I got the error message

'DataFrame' object has no attribute 'write'

Can you please help me to resolve the issue?

1 Answers

Hope this would help

myCSV= spark.read.csv("/path/to/input/data",header=True,sep=","); 
myCSV.write.format("delta").mode("overwrite").option('overwriteSchema','true').save("/mnt/delta/Employee") 
spark.sql("CREATE TABLE employee USING DELTA LOCATION '/mnt/delta/Employee/'")
Related