Example Usage for DataFrame

Initialize

object id: 1265613381480
columns:
[]
data:
[]
index:
[]
object id: 1265613381568
columns:
['a', 'b', 'c']
data:
[[None, None, None], [None, None, None], [None, None, None]]
index:
[1, 2, 3]
object id: 1265613380600
columns:
['a', 'b']
data:
[[1, 2, 3], [4, 5, 6]]
index:
[10, 11, 12]

Print

  index    a    b
-------  ---  ---
     10    1    4
     11    2    5
     12    3    6
  index    a    b
-------  ---  ---
     10    1    4
     11    2    5
     12    3    6

Setters and Getters

['a', 'b']
  index    first    second
-------  -------  --------
     10        1         4
     11        2         5
     12        3         6
['a', 'b']
[10, 11, 12]
index      a    b
-------  ---  ---
apple      1    4
pear       2    5
7.7        3    6
  index    a    b
-------  ---  ---
     10    1    4
     11    2    5
     12    3    6
'index'
'units'
[[1, 2, 3], [4, 5, 6]]

Select Index

[False, True, False]

Set Values

  index    a    b
-------  ---  ---
     10  100    4
     11    2    5
     12    3    6
  index    a    b    c
-------  ---  ---  ---
     10  100    4
     11    2    5
     12    3    6
     13              9
  index    a    b    c
-------  ---  ---  ---
     10  100   55
     11    2   55
     12    3   55
     13        55    9
  index    a    b    c
-------  ---  ---  ---
     10  100   66
     11    2   55
     12    3   66
     13        55    9
  index    a    b    c
-------  ---  ---  ---
     10  100   88
     11    2   55
     12    3   99
     13        55    9
  index    a    b    c
-------  ---  ---  ---
     10  100   88
     11    2   55
     12   33   99
     13   33   55    9
  index    a    b    c
-------  ---  ---  ---
     10  100   88    1
     11    2   55    2
     12   33   99    3
     13   33   55    9
  index    a    b    c    d
-------  ---  ---  ---  ---
     10  100   88    1
     11    2   55    2
     12   33   99    3
     13   33   55    9
     14   44       100   99
  index    a    b    c    d
-------  ---  ---  ---  ---
     10  100   88    1
     11    2   55    2
     12   33   99    3
     13   33   55    9
     14   44       100   99
     15   55            100
     16   56            101

Get Values

100
  index    c
-------  ---
     10    1
     11    2
     12    3
     13    9
     14  100
     15
     16
  index    a    c
-------  ---  ---
     10  100    1
     11    2    2
     12   33    3
     13   33    9
     14   44  100
     15   55
     16   56
  index    b
-------  ---
     11   55
     12   99
     13   55
  index    b
-------  ---
     11   55
     12   99
     13   55
  index    a    c
-------  ---  ---
     10  100    1
     11    2    2
[100, 2, 33, 33, 44, 55, 56]
{'a': 33, 'b': 55, 'index': 13}

Set and Get by Location

Locations are the index of the index, in other words the index locations from 0…len(index)

33
  index    a    b    c  d
-------  ---  ---  ---  ---
     12   33   99    3
{'b': 88, 'c': 1, 'index': 10}
  index    a  b    c      d
-------  ---  ---  ---  ---
     16   56            101
  index    a    b    c  d
-------  ---  ---  ---  ---
     10  100   88    1
     12   33   99    3
  index    a    b    c    d
-------  ---  ---  ---  ---
     10   -9   88    1
     11    2   55    2
     12   -9   99    3
     13   33   55    9
     14   44       100   99
     15   55            100
     16   56            101

Head and Tail

  index    a    b    c  d
-------  ---  ---  ---  ---
     10   -9   88    1
     11    2   55    2
  index    a  b    c      d
-------  ---  ---  ---  ---
     15   55            100
     16   56            101

Delete colunmns and rows

  index    a    b    c    d
-------  ---  ---  ---  ---
     11    2   55    2
     12   -9   99    3
     14   44       100   99
     15   55            100
     16   56            101
  index    a    c    d
-------  ---  ---  ---
     11    2    2
     12   -9    3
     14   44  100   99
     15   55       100
     16   56       101

Convert

{'a': [2, -9, 44, 55, 56],
 'c': [2, 3, 100, None, None],
 'd': [None, None, 99, 100, 101],
 'index': [11, 12, 14, 15, 16]}
{'a': [2, -9, 44, 55, 56],
 'c': [2, 3, 100, None, None],
 'd': [None, None, 99, 100, 101]}
OrderedDict([('index', [11, 12, 14, 15, 16]),
             ('a', [2, -9, 44, 55, 56]),
             ('c', [2, 3, 100, None, None]),
             ('d', [None, None, 99, 100, 101])])
[2, 3, 100, None, None]
{"data": {"a": [2, -9, 44, 55, 56], "c": [2, 3, 100, null, null], "d": [null, null, 99, 100, 101]}, "index": [11, 12, 14, 15, 16], "meta_data": {"index_name": "index", "columns": ["a", "c", "d"], "sort": false, "use_blist": false}}
  index    a    c    d
-------  ---  ---  ---
     11    2    2
     12   -9    3
     14   44  100   99
     15   55       100
     16   56       101

Sort by Index and Column

  index    a    b
-------  ---  ---
     25    4    6
     24    3    7
     23    2    8
     22    1    9
  index    a    b
-------  ---  ---
     22    1    9
     23    2    8
     24    3    7
     25    4    6
  index    a    b
-------  ---  ---
     25    4    6
     24    3    7
     23    2    8
     22    1    9
  index    a    b
-------  ---  ---
     22    1    9
     23    2    8
     24    3    7
     25    4    6

Append

  index    a    b
-------  ---  ---
      1    1    5
      2    2    6
  index    b    c
-------  ---  ---
      3    7   11
      4    8   12
  index    a    b    c
-------  ---  ---  ---
      1    1    5
      2    2    6
      3         7   11
      4         8   12

Math Methods

[False, False, True]
[False, False]
[3, 10, 12]
[1, 6, 6]
[2, 27]
[2.0, 4.0, 3.0]

Multi-Index

Raccoon does not have true hierarchical mulit-index capabilities like Pandas, but attempts to mimic some of the capabilities with the use of tuples as the index. Raccoon does not provide any checking to make sure the indexes are all the same length or any other integrity checking.

index          a
-----------  ---
('a', 1, 3)    1
('a', 1, 4)    2
('a', 2, 3)    3
('b', 1, 4)    4
('b', 2, 1)    5
('b', 3, 3)    6

The select_index method works with tuples by allowing the * to act as a wild card for matching.

[True, True, True, False, False, False]
[True, False, True, False, False, False]
[('a', 2, 3), ('b', 2, 1)]
[('a', 1, 3), ('a', 2, 3), ('b', 3, 3)]
[True, True, True, True, True, True]

Reset Index

  index    a    b
-------  ---  ---
      0    1    4
      1    2    5
      2    3    6
object id: 1265615259432
columns:
['a', 'b', 'index_0']
data:
[[1, 2, 3], [4, 5, 6], [0, 1, 2]]
index:
[0, 1, 2]
jelo      a    b
------  ---  ---
x         1    4
y         2    5
z         3    6
  index    a    b  jelo
-------  ---  ---  ------
      0    1    4  x
      1    2    5  y
      2    3    6  z
('melo', 'helo', 'gelo')      a    b
--------------------------  ---  ---
('a', 10, 'x')                1    4
('b', 11, 'y')                2    5
('c', 12, 'z')                3    6
  index    a    b  melo      helo  gelo
-------  ---  ---  ------  ------  ------
      0    1    4  a           10  x
      1    2    5  b           11  y
      2    3    6  c           12  z
jelo      a    b
------  ---  ---
x         1    4
y         2    5
z         3    6
  index    a    b
-------  ---  ---
      0    1    4
      1    2    5
      2    3    6

Iterators

{'index': 1, 'a': 1, 'b': 5}
{'index': 2, 'a': 2, 'b': 6}
{'index': 3, 'a': 'c', 'b': 'd'}
Raccoon(index=1, a=1, b=5)
Raccoon(index=2, a=2, b=6)
Raccoon(index=3, a='c', b='d')

Sorted DataFrames

DataFrames will be set to sorted by default if no index is given at initialization. If an index is given at initialization then the parameter sorted must be set to True

When sorted=True on initialization the data will be sorted by index to start

  index    a    b
-------  ---  ---
     12    3    6
     14    4    7
     15    5    8
  index    a    b
-------  ---  ---
     12    3    6
     14    4    7
     15    5    8
     16         9
  index    a    b
-------  ---  ---
     12  3    6
     13  3.5  6.5
     14  4    7
     15  5    8
     16       9

List or BList

The underlying data structure can be either blist (default) or list

blist([blist([1, 2, 3])])
blist([5, 6, 7])
blist(['a'])
[[1, 2, 3]]
[5, 6, 7]
['a']