Skip to content

Instantly share code, notes, and snippets.

View Shekharrajak's full-sized avatar
📚
Being Geek!

Shekhar Prasad Rajak Shekharrajak

📚
Being Geek!
View GitHub Profile

Data Analysis and Visualisation in Ruby with daru

In this talk we will be learning about Ruby gem daru (Data Analysis in RUby); a library for storage, analysis, manipulation and visualisation of data. We will learn about simple and fast techniques to import & analyse data sets, exporting data and plotting charts for gaining quick insights into your data, using daru dataframe. Also we will see how daru gem is useful in Ruby framework web applications (e.g. Rails/Sinatra/Nanoc) to directly analyse/manipulate data and display interactive charts to visualise the informations, which helps users to understand it better.

Outlines

  • Introducing myself
  • What is daru ?
  • Why to use daru and what makes it powerful gem for data analysis and visualisation ?
require 'pivot_table'
require 'daru'
class Order
attr_reader :city, :quarter, :top_sales
def initialize args
args.each do |k,v|
instance_variable_set("@#{k}", v) unless v.nil?
end
end
# code from sympy.diophantine
for solution in solns_pell:
for X_i in [-solution[0], solution[0]]:
for Y_i in [-solution[1], solution[1]]:
s = P*Matrix([X_i, Y_i]) + Q
try:
sol.add(tuple([as_int(_) for _ in s]))
except ValueError:
# args = list(FiniteSet(*args))
length = len(args)
reduced = [[None for x in range(length)] for x in range(length)]
# base case
reduced[0][0] = [args[0]]
# first row
for i in range(1, length - 1):
new_set = reduced[0][i - 1][0]._union(args[i])
if new_set is not None:
reduced[0][i] = [new_set]
@Shekharrajak
Shekharrajak / trig_general_union_PR11188.py
Created August 14, 2016 04:20
logic which is changed to issuperset
# logic for imageSet union
# img1 = ImageSet(Lambda(n, a*n + b), S.Integers)
# img2 = ImageSet(Lambda(n, c*n + d), S.Integers)
# When a != c and (c + (b - d)) mod a == 0, means (c + (b-d))*n may be multiple of a*n.
# After checking it for 3 values, returns img1.
# In [1]: Union(ImageSet(Lambda(n, 3*n), S.Integers), ImageSet(Lambda(n, 6*n), S.Integers))
# Out[1]: {3⋅n | n ∊ ℤ}
# In [2]: Union(ImageSet(Lambda(n, 3*n ), S.Integers), ImageSet(Lambda(n, 7*n ), S.Integers))
# master branch
In [1]: solveset(cos(x) + cos(3*x) + cos(5*x), x, S.Reals)
Out[1]:
⎧ π ⎫ ⎧ 3⋅π ⎫ ⎧ 4⋅π ⎫ ⎧ 2⋅π ⎫ ⎧ 5⋅π ⎫ ⎧ π ⎫ ⎧
⎨2⋅n⋅π + ─ | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─ | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π +
⎩ 2 ⎭ ⎩ 2 ⎭ ⎩ 3 ⎭ ⎩ 3 ⎭ ⎩ 3 ⎭ ⎩ 3 ⎭ ⎩
7⋅π ⎫ ⎧ 5⋅π ⎫ ⎧ 11⋅π ⎫ ⎧ π ⎫
─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ──── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─ | n ∊ ℤ⎬
def _union(self, other):
"""
This function should only be used internally.
See Set._union for docstring
Used within the :class:`Union` class
This function club imageset `other` with `self` if there is difference
of `pi` or `2*pi` and returns this new imageset otherwise None.
# examples how we can use factor to reduce number of imageset :
# current master branch
In [110]: solveset(4*sin(x)**3 + 2*sin(x)**2 - 2*sin(x) - 1) # ------------ eq(1)
Out[110]:
⎧ 7⋅π ⎫ ⎧ 11⋅π ⎫ ⎧ 5⋅π ⎫ ⎧ 3⋅π ⎫ ⎧ 7⋅π ⎫ ⎧ π ⎫
⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ──── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─ | n ∊ ℤ⎬
⎩ 6 ⎭ ⎩ 6 ⎭ ⎩ 4 ⎭ ⎩ 4 ⎭ ⎩ 4 ⎭ ⎩ 4 ⎭
In [123]: solveset((4*sin(x)**3 + 2*sin(x)**2 - 2*sin(x) - 1).rewrite(exp))
# in fancyset/ImageSet class
lamda_vars = property(lambda self: self.lamda.variables)
def put_values(self, symbol, val=None):
"""
Returns ImageSet expr value in FiniteSet after substituting the given
`values` for `symbol`.
Input can be either a single symbol and corresponding value
or a dictionary of symbols and values. If symbol(s) are present in