How to Create A Dataframe Of Zeros in Python
To create a dataframe of zeros in Python, you can use the pandas.DataFrame() function.
The following example shows how to create a dataframe of zeros in Python using the pandas.DataFrame() function.
Using pandas.DataFrame() Function
We can use the pandas.DataFrame() function to create a dataframe of zeros.
Suppose we have the following dimensions:
# Import pandas library
import pandas as pd
# Declare rows and columns
rows, columns = 6, 5
# Create Pandas DataFrame
df = pd.DataFrame(0, index=range(rows), columns=range(columns))
# Print DataFrame
print(df)
Output: 👇️
0 1 2 3 4
0 0 0 0 0 0
1 0 0 0 0 0
2 0 0 0 0 0
3 0 0 0 0 0
4 0 0 0 0 0
5 0 0 0 0 0
In this example, we use the pandas.DataFrame() function to create a dataframe df with zero values.
The output shows the dataframe created with zeros.
Conclusion
We can use the pandas.DataFrame() function to create a dataframe of zeros in Python.