Python Pandas – Creating a Zero-Filled DataFrame

dataframepandaspython

What is the best way to create a zero-filled pandas data frame of a given size?

I have used:

zero_data = np.zeros(shape=(len(data),len(feature_list)))
d = pd.DataFrame(zero_data, columns=feature_list)

Is there a better way to do it?

Best Answer

Create and fill a pandas dataframe with zeros

feature_list = ["foo", "bar", 37]
df = pd.DataFrame(0, index=np.arange(7), columns=feature_list) 
print(df) 

which prints:

   foo  bar  37
0    0    0   0
1    0    0   0
2    0    0   0
3    0    0   0
4    0    0   0
5    0    0   0
6    0    0   0
Related Question