require 'daru' df = Daru::DataFrame.from_csv '/home/sameer/github_repos/daru/spec/fixtures/music_data.tsv', col_sep: "\t" df.timestamp.map! { |ts| ts += "+5:30"} require 'date' df = df.map_rows do |row| row[:timestamp] = DateTime.strptime(row[:timestamp], '%Y-%m-%dT%H:%M:%SZ%z').to_time row end artist_counts = {} # Populate a hash which has artist names as keys with corresponding values set to the number of times the name of the artist # has appeared. artists = df.artname.uniq artists.each do |artist| artist_counts[artist] = df.artname.count(artist) end # Since indexes are stored as symbols, convert each artist name to camel_case a= artist_counts.to_a.each do |name_val_pair| name_val_pair[0] = name_val_pair[0].downcase.split(' ').join('_') end counts = Daru::Vector.new Hash[a], name: :counts counts.max :vector top_ten = counts.sort[-10..-1] hsh = {} top_ten.each do |count| hsh[counts.index_of(count)] = count end ten = Daru::Vector.new hsh ten.plot type: :bar, width: 1120, height: 300