Creating a zero-filled pandas data frame

前端 未结 6 1803
情书的邮戳
情书的邮戳 2020-12-07 14:36

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)         


        
6条回答
  •  情话喂你
    2020-12-07 15:03

    Similar to @Shravan, but without the use of numpy:

      height = 10
      width = 20
      df_0 = pd.DataFrame(0, index=range(height), columns=range(width))
    

    Then you can do whatever you want with it:

    post_instantiation_fcn = lambda x: str(x)
    df_ready_for_whatever = df_0.applymap(post_instantiation_fcn)
    

提交回复
热议问题