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.
Showing results for 
Search instead for 
Did you mean: 


New Contributor III

How can we create empty dataframe in databricks and how many ways we can create dataframe?


Not applicable

@Govardhana Reddy​ :

Method 1:

from pyspark.sql import SparkSession
spark = SparkSession.builder.appName("MyApp").getOrCreate()
# Create an empty DataFrame with a specified schema
empty_df = spark.createDataFrame([], schema=["column1", "column2", "column3"])

Method 2: From dictionary

data = [
  {"name": "Alice", "age": 25},
  {"name": "Bob", "age": 30},
  {"name": "Charlie", "age": 35}
df = spark.createDataFrame(data)

Method 3: From list of tuples

data = [("Alice", 25), ("Bob", 30), ("Charlie", 35)]
df = spark.createDataFrame(data, schema=["name", "age"])

Method 4: From Pandas dataframe

import pandas as pd
pdf = pd.DataFrame({
  "name": ["Alice", "Bob", "Charlie"],
  "age": [25, 30, 35]
df = spark.createDataFrame(pdf)

Method 5: from cvs file

df ="path/to/file.csv", header=True, inferSchema=True)

Method 6: From parquet file

df ="path/to/file.parquet")


Hi @Govardhana Reddy​ 

Hope everything is going great.

Does @Suteja Kanuri​'s answer help? If yes, would you be happy to mark an answer as best so that other members can find the solution more quickly? If not, please tell us so we can help you. 


Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!