require 'daru' require 'distribution' require 'gnuplotrb' vector = Daru::Vector.new( [20,40,25,50,45,12], index: ['cherry', 'apple', 'barley', 'wheat', 'rice', 'sugar'], name: "Prices of stuff.") vector['rice'] vector['rice', 'wheat', 'sugar'] vector['barley'..'sugar'] vector['barley'] = 1500 vector df = Daru::DataFrame.new({ 'col0' => [1,2,3,4,5,6], 'col2' => ['a','b','c','d','e','f'], 'col1' => [11,22,33,44,55,66] }, index: ['one', 'two', 'three', 'four', 'five', 'six'], order: ['col0', 'col1', 'col2'] ) df['col1'] df['col2', 'col0'] df['col1'..'col2'] df['col1'] = Daru::Vector.new(['this', 'is', 'some','new','data','here'], index: ['one', 'three','two','six','four', 'five']) df df.row['four'] df.row['three'..'five'] df.row['five'] = [666,555,333] vector = Daru::Vector.new([1,3,5,nil,2,53,nil]) vector.mean df.mean df.describe index = Daru::DateTimeIndex.date_range(:start => '2012', :periods => 1000, :freq => '3D') timeseries = Daru::Vector.new(1000.times.map {rand}, index: index) timeseries['2012'] timeseries['2012-3'] timeseries['2012-3-10'] index = Daru::DateTimeIndex.date_range( :start => '2012-3-23 11:00', :periods => 20000, :freq => 'S') seconds_ts = Daru::Vector.new(20000.times.map { rand(50) }, index: index) seconds_ts['2012-3-23 12:42'] df = Daru::DataFrame.new({ :temperature => [30.4, 23.5, 44.5, 20.3, 34, 24, 31.45, 28.34, 37, 24], :sales => [350, 150, 500, 200, 480, 250, 330, 400, 420, 560], :city => ['Pune', 'Delhi']*5, :staff => [15,20]*5 }) df df.plot(type: :scatter, x: :temperature, y: :sales) do |plot, diagram| plot.x_label "Temperature" plot.y_label "Sales" plot.yrange [100, 600] plot.xrange [15, 50] diagram.tooltip_contents([:city, :staff]) # Set the color scheme for this diagram. diagram.color(Nyaplot::Colors.qual) # Change color of each point WRT to the city that it belongs to. diagram.fill_by(:city) # Shape each point WRT to the city that it belongs to. diagram.shape_by(:city) end rng = Distribution::Normal.rng index = Daru::DateTimeIndex.date_range(:start => '2012-4-2', :periods => 1000) vector = Daru::Vector.new(1000.times.map {rng.call}, index: index) vector = vector.cumsum rolling_mean = vector.rolling_mean 60 GnuplotRB::Plot.new( [vector , with: 'lines', title: 'Vector'], [rolling_mean, with: 'lines', title: 'Rolling Mean'], xlabel: 'Time', ylabel: 'Value' ) df = Daru::DataFrame.new({ a: [1,2,3,4,5,6]*100, b: ['a','b','c','d','e','f']*100, c: [11,22,33,44,55,66]*100 }, index: (1..600).to_a.shuffle) df df.where(df[:a].eq(2).or(df[:c].eq(55)))