How to Create a DataFrame in Python
A DataFrame is one of the most commonly used data structures in the Pandas library. It represents data in a tabular format, where information is arranged into rows and columns, similar to a spreadsheet or database table.
DataFrames are widely used in Python for tasks such as data cleaning, filtering, analysis, transformation, and visualization. Pandas provides several ways to build a DataFrame depending on the type and structure of your data.
In this tutorial, we will learn different methods to create a DataFrame in Python using Pandas, including lists, dictionaries, Series, custom indexes, and the zip() function.
Table of Contents

YT:- DecodeIT
Installing Pandas
Before working with DataFrames, you need to have Pandas installed in your Python environment. If it is not already installed, run the following command in your terminal:
pip install pandas
Once Pandas has been installed, import it into your Python program using:
import pandas as pd
1. Create an Empty DataFrame
The simplest DataFrame contains no data. You can create one by calling pd.DataFrame() without passing any values.
import pandas as pd
df = pd.DataFrame()
print(df)
Output
Empty DataFrame
Columns: []
Index: []
This creates a DataFrame without rows or columns. Data can be added later as required.
2. Create a DataFrame from a List
A list can be directly passed to the DataFrame constructor. In this case, each item in the list becomes a row.
import pandas as pd
languages = [
"Java",
"Python",
"C",
"C++",
"JavaScript",
"Swift",
"Go"
]
df = pd.DataFrame(languages, columns=["Programming Language"])
print(df)
Output
Programming Language
0 Java
1 Python
2 C
3 C++
4 JavaScript
5 Swift
6 Go
The columns parameter gives a name to the DataFrame column.
3. Create a DataFrame from a Dictionary of Lists
A dictionary containing lists is another common way to construct a DataFrame. The dictionary keys become column names, while the list values form the data inside those columns.
import pandas as pd
data = {
"Name": ["Tom", "Joseph", "Krish", "John"],
"Age": [20, 21, 19, 18]
}
df = pd.DataFrame(data)
print(df)
Output
Name Age
0 Tom 20
1 Joseph 21
2 Krish 19
3 John 18
Here, Name and Age become the column labels, and each position in the lists represents a row.
4. Create a DataFrame with Custom Indexes
By default, Pandas assigns numbers such as 0, 1, and 2 as row indexes. You can replace these default indexes with your own labels while creating the DataFrame.
import pandas as pd
data = {
"Name": ["Renault", "Duster", "Maruti", "Honda City"],
"Ratings": [9.0, 8.0, 5.0, 3.0]
}
df = pd.DataFrame(
data,
index=["Position1", "Position2", "Position3", "Position4"]
)
print(df)
Output
Name Ratings
Position1 Renault 9.0
Position2 Duster 8.0
Position3 Maruti 5.0
Position4 Honda City 3.0
The index parameter allows you to specify custom labels for the rows.
5. Create a DataFrame from a List of Dictionaries
You can also provide Pandas with a list containing multiple dictionaries. The keys from the dictionaries are treated as column names.
import pandas as pd
data = [
{"A": 10, "B": 20, "C": 30},
{"x": 100, "y": 200, "z": 300}
]
df = pd.DataFrame(data)
print(df)
Output
A B C x y z
0 10.0 20.0 30.0 NaN NaN NaN
1 NaN NaN NaN 100.0 200.0 300.0
Since the two dictionaries contain different keys, Pandas creates columns for all of them. Where a particular dictionary does not provide a value, Pandas uses NaN to represent the missing data.
6. Create a DataFrame Using zip()
The zip() function is useful when your data is stored in separate lists. It combines corresponding elements from the lists into pairs, which can then be passed to Pandas.
import pandas as pd
names = ["Tom", "Krish", "Arun", "Juli"]
marks = [95, 63, 54, 47]
data = list(zip(names, marks))
df = pd.DataFrame(data, columns=["Name", "Marks"])
print(df)
Output
Name Marks
0 Tom 95
1 Krish 63
2 Arun 54
3 Juli 47
In this example, each name is paired with the mark at the same position. These pairs are then converted into DataFrame rows.
7. Create a DataFrame from a Dictionary of Series
Pandas Series objects can also be combined into a DataFrame by placing them inside a dictionary. The dictionary keys become the column names, while the Series indexes determine the row labels.
import pandas as pd
data = {
"Electronics": pd.Series(
[97, 56, 87, 45],
index=["John", "Abhinay", "Peter", "Andrew"]
),
"Civil": pd.Series(
[97, 88, 44, 96],
index=["John", "Abhinay", "Peter", "Andrew"]
)
}
df = pd.DataFrame(data)
print(df)
Output
Electronics Civil
John 97 97
Abhinay 56 88
Peter 87 44
Andrew 45 96
Because both Series use the same index labels, Pandas aligns their values correctly when constructing the DataFrame.
Why Use a Pandas DataFrame?
DataFrames make it convenient to work with structured data. They provide operations for selecting columns, filtering rows, handling missing values, modifying records, and performing calculations.
This makes DataFrames especially useful in data analysis, machine learning, data science, and applications that work with tabular datasets.
Complete Advance AI Topics: Click Here
SQL Tutorial: Click Here
Conclusion
Python’s Pandas library provides several convenient ways to create a DataFrame. You can start with an empty DataFrame, build one from a list or dictionary, provide custom indexes, combine multiple dictionaries, use zip() with separate lists, or construct a DataFrame from a dictionary of Pandas Series.
Understanding these different approaches helps you choose a suitable method based on how your data is stored. Once a DataFrame has been created, Pandas provides many tools for cleaning, transforming, analyzing, and managing that data.
Frequently Asked Questions
How do I create a DataFrame in Python?
You can create a DataFrame using the Pandas DataFrame() constructor, such as pd.DataFrame(data).
How do I create an empty DataFrame?
Use pd.DataFrame() without providing any data:
df = pd.DataFrame()
How do I create a DataFrame from a list?
Pass the list to pd.DataFrame() and optionally specify a column name using the columns parameter.
How do I create a DataFrame from a dictionary?
You can pass a dictionary containing lists directly to pd.DataFrame(). The dictionary keys become the column names.
Can I create a DataFrame from two lists?
Yes. You can combine the lists with zip() and then pass the resulting data to pd.DataFrame().
How can I add custom row indexes?
Use the index parameter while creating the DataFrame to provide your own row labels.
Keywords
How to Create a DataFrame in Python, create Pandas DataFrame from list, DataFrame in Python example, create empty DataFrame with column names, Pandas create empty DataFrame, Pandas DataFrame tutorial, how to create a DataFrame in Python, create DataFrame in Python with column names, create DataFrame in Python from dictionary, create DataFrame in Python from CSV, create DataFrame in Python from list, create DataFrame in Python with two lists, create DataFrame using Pandas, Python Pandas DataFrame, create DataFrame from dictionary of lists, create DataFrame from list of dictionaries