Reading csv from windows C drive in Azure databricks

Viewed 272

I am trying to read a .csv file from windows C drive to databricks. I tried the following code after going through some of the answers.

# remove the 'file' string and use 'r' or 'u' prefix to indicate raw/unicore string format
# Option 1
#PATH = r'C:\customers_marketing.csv'  # raw string
# Option 2
PATH = u'C:\\customers_marketing.csv' # unicode string
customers_marketing = spark.read.csv(PATH, header="true", inferSchema="true")

However, I was not able to read it to databricks. I get the following error.

IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: C:%5Ccustomers_marketing.csv

Could anyone pls advise/suggest how can I read data from windows c drive to databricks.

Thanks in advance

1 Answers

It's not possible, because your file is on your local machine, and Databricks is in the cloud, without any knowledge about your machine.

You need to upload file onto DBFS, and then read from it. You can do it for example via UI - via DBFS file browser (docs) or via Upload Data UI (docs)

If the file is huge, then you need to use something like az-copy to upload file(s) to Azure Storage

Related