@@ -1587,22 +1587,21 @@ def join(other_df,opts={})
1587
1587
# to new dataset, and fields which responds to second
1588
1588
# pattern will be added one case for each different %n.
1589
1589
#
1590
- # == Usage
1590
+ # @example
1591
1591
# cases=[
1592
1592
# ['1','george','red',10,'blue',20,nil,nil],
1593
1593
# ['2','fred','green',15,'orange',30,'white',20],
1594
1594
# ['3','alfred',nil,nil,nil,nil,nil,nil]
1595
1595
# ]
1596
1596
# ds=Daru::DataFrame.rows(cases, order: [:id, :name, :car_color1, :car_value1, :car_color2, :car_value2, :car_color3, :car_value3])
1597
1597
# ds.one_to_many([:id],'car_%v%n').to_matrix
1598
- # => Matrix[
1599
- # ["red", "1", 10],
1600
- # ["blue", "1", 20],
1601
- # ["green", "2", 15],
1602
- # ["orange", "2", 30],
1603
- # ["white", "2", 20]
1604
- # ]
1605
- #
1598
+ # #=> Matrix[
1599
+ # # ["red", "1", 10],
1600
+ # # ["blue", "1", 20],
1601
+ # # ["green", "2", 15],
1602
+ # # ["orange", "2", 30],
1603
+ # # ["white", "2", 20]
1604
+ # # ]
1606
1605
def one_to_many ( parent_fields , pattern )
1607
1606
re = Regexp . new pattern . gsub ( "%v" , "(.+?)" ) . gsub ( "%n" , "(\\ d+?)" )
1608
1607
ds_vars = parent_fields . dup
@@ -1670,14 +1669,14 @@ def add_vectors_by_split_recode(name_, join='-', sep=Daru::SPLIT_TOKEN)
1670
1669
# * table - String specifying name of the table that will created in SQL.
1671
1670
# * charset - Character set. Default is "UTF8".
1672
1671
#
1673
- # == Usage
1672
+ # @example
1674
1673
#
1675
1674
# ds = Daru::DataFrame.new({
1676
1675
# :id => Daru::Vector.new([1,2,3,4,5]),
1677
1676
# :name => Daru::Vector.new(%w{Alex Peter Susan Mary John})
1678
1677
# })
1679
1678
# ds.create_sql('names')
1680
- # = =>"CREATE TABLE names (id INTEGER,\n name VARCHAR (255)) CHARACTER SET=UTF8;"
1679
+ # # =>"CREATE TABLE names (id INTEGER,\n name VARCHAR (255)) CHARACTER SET=UTF8;"
1681
1680
#
1682
1681
def create_sql ( table , charset = "UTF8" )
1683
1682
sql = "CREATE TABLE #{ table } ("
@@ -1740,6 +1739,8 @@ def to_a
1740
1739
arry
1741
1740
end
1742
1741
1742
+ # Convert to json. If no_index is false then the index will NOT be included
1743
+ # in the JSON thus created.
1743
1744
def to_json no_index = true
1744
1745
if no_index
1745
1746
self . to_a [ 0 ] . to_json
@@ -1814,12 +1815,9 @@ def update
1814
1815
@data . each { |v | v . update } if Daru . lazy_update
1815
1816
end
1816
1817
1818
+ # Rename the DataFrame.
1817
1819
def rename new_name
1818
- if new_name . is_a? ( Numeric )
1819
- @name = new_name
1820
- return
1821
- end
1822
- @name = new_name . to_sym
1820
+ @name = new_name
1823
1821
end
1824
1822
1825
1823
# Write this DataFrame to a CSV file.
0 commit comments