0

I need to create an empty DataFrame with an specific shape for example [10,10] to store data from other source.

In pandas is straightforward:

pd.DataFrame(np.nan, index=range(10), columns=range(10))

But in ruby using daru, I'm not sure how to do that.

Related Question: pandas Dataframe

4

1 回答 1

3

您可以在选项中传递向量的名称,并在:order选项中传递范围作为索引:index。输入将为空Array

例如:

require 'daru'
df = Daru::DataFrame.new([], order: (1..4).to_a, index:(0..10).to_a)
# => 
#<Daru::DataFrame:72941700 @name = 2357edc1-f425-4ae3-aead-5a8b812ecb13 @size = 11>
#                    1          2          3          4 
#         0        nil        nil        nil        nil 
#         1        nil        nil        nil        nil 
#         2        nil        nil        nil        nil 
#         3        nil        nil        nil        nil 
#         4        nil        nil        nil        nil 
#         5        nil        nil        nil        nil 
#         6        nil        nil        nil        nil 
#         7        nil        nil        nil        nil 
#         8        nil        nil        nil        nil 
#         9        nil        nil        nil        nil 
#        10        nil        nil        nil        nil 
于 2015-12-20T19:29:17.380 回答