This article describes how to import data into Databricks using the UI, read imported data using the Spark and local APIs, and modify imported data using Databricks File System (DBFS) commands.
If you have small data files on your local machine that you want to analyze with Databricks, you can easily import them to Databricks File System (DBFS) using the UI:
Drop files into or browse to files in the Import & Explore Data box on the landing page:
Upload the files in the Create table UI.
Files imported to DBFS using one of these methods are stored in FileStore.
You can also use a wide variety of data sources to access data.
You read data imported to DBFS into Apache Spark DataFrames using Spark APIs. For example, if you import a CSV file, you can read the data using one of these examples.
For easier access, we recommend that you create a table. See Databases and tables for more information.
val sparkDF = spark.read.format("csv") .option("header", "true") .option("inferSchema", "true") .load("/FileStore/tables/state_income-9f7c5.csv")
sparkDF = spark.read.csv('/FileStore/tables/state_income-9f7c5.csv', header="true", inferSchema="true")
sparkDF <- read.df(source = "csv", path = "/FileStore/tables/state_income-9f7c5.csv", header="true", inferSchema = "true")
You can also read data imported to DBFS in programs running on the Spark driver node using local file APIs. For example:
pandas_df = pd.read_csv("/dbfs/FileStore/tables/state_income-9f7c5.csv", header='infer')
df = read.csv("/dbfs/FileStore/tables/state_income-9f7c5.csv", header = TRUE)
To delete data from DBFS, use the same APIs and tools. For example, you can use the Databricks Utilities command
Deleted data cannot be recovered.