In [1]:
    
# remove comment to use latest development version
import sys; sys.path.insert(0, '../')
    
In [2]:
    
# import libraries
import raccoon as rc
    
In [3]:
    
# empty DataFrame
srs = rc.Series()
srs
    
    Out[3]:
In [4]:
    
# with indexes but no data
srs = rc.Series(index=[1, 2, 3])
srs
    
    Out[4]:
In [5]:
    
# with data
srs = rc.Series(data=[4, 5, 6], index=[10, 11, 12])
srs
    
    Out[5]:
In [6]:
    
srs.print()
    
    
In [7]:
    
print(srs)
    
    
In [8]:
    
# data_name
srs.data_name
    
    Out[8]:
In [9]:
    
srs.data_name = 'new_data'
print(srs)
    
    
In [10]:
    
# index
srs.index
    
    Out[10]:
In [11]:
    
#indexes can be any non-repeating unique values
srs.index = ['apple', 'pear', 7.7]
srs.print()
    
    
In [12]:
    
srs.index = [10, 11, 12]
print(srs)
    
    
In [13]:
    
# the index can also have a name, befault it is "index"
srs.index_name
    
    Out[13]:
In [14]:
    
srs.index_name = 'units'
srs.index_name
    
    Out[14]:
In [15]:
    
# data is a shallow copy, be careful on how this is used
srs.index_name = 'index'
srs.data
    
    Out[15]:
In [16]:
    
srs.select_index(11)
    
    Out[16]:
In [17]:
    
# set a single cell
srs.set(10, 100)
print(srs)
    
    
In [18]:
    
# set a value outside current range creates a new row. Can also use [] for setting
srs[13] = 9
srs.print()
    
    
In [19]:
    
# set a subset of rows
srs[[10, 12]] = 66
print(srs)
    
    
In [20]:
    
# using boolean list
srs.set([True, False, True, False], [88, 99])
print(srs)
    
    
In [21]:
    
# setting with slices
srs[12:13] = 33
print(srs)
    
    
In [22]:
    
srs[10:12] = [1, 2, 3]
print(srs)
    
    
In [23]:
    
# set a location
srs.set_location(1, 22)
print(srs)
    
    
In [24]:
    
# set multiple locations
srs.set_locations([0, 2], [11, 27])
print(srs)
    
    
In [25]:
    
# append a row, DANGEROUS as there is not validation checking, but can be used for speed
srs.append_row(14, 99)
print(srs)
    
    
In [26]:
    
# append multiple rows, again no sort check
srs.append_rows([15, 16], [100, 110])
print(srs)
    
    
In [27]:
    
# get a single cell
srs[10]
    
    Out[27]:
In [28]:
    
# get subset of the index
srs[[11, 12, 13]].print()
    
    
In [29]:
    
# get using slices
srs[11:13].print()
    
    
In [30]:
    
# return as a list
srs.get([11, 12, 13], as_list=True)
    
    Out[30]:
In [31]:
    
print(srs.get_location(2))
    
    
In [32]:
    
srs.get_location(-1)
    
    Out[32]:
In [33]:
    
srs.get_locations(locations=[0, 2]).print()
    
    
In [34]:
    
srs.get_locations(locations=[0, 2], as_list=True)
    
    Out[34]:
In [35]:
    
srs.set_locations([-1, -2], values=[10, 9])
print(srs)
    
    
In [36]:
    
srs.head(2).print()
    
    
In [37]:
    
srs.tail(2).print()
    
    
In [38]:
    
srs.delete([10, 13])
print(srs)
    
    
In [39]:
    
# return a dict
srs.to_dict()
    
    Out[39]:
In [40]:
    
# exclude the index
srs.to_dict(index=False)
    
    Out[40]:
In [41]:
    
# return an OrderedDict()
srs.to_dict(ordered=True)
    
    Out[41]:
In [42]:
    
srs = rc.Series([6, 7, 8, 9], index=[25, 24, 23, 22])
print(srs)
    
    
In [43]:
    
# sort by index. Sorts are inplace
srs.sort_index()
print(srs)
    
    
In [44]:
    
srs = rc.Series([1, 2, 3])
    
In [45]:
    
# test for equality
srs.equality(value=3)
    
    Out[45]:
In [46]:
    
# all math methods can operate on a subset of the index
srs.equality(indexes=[1, 2], value=2)
    
    Out[46]:
In [47]:
    
tuples = [('a', 1, 3), ('a', 1, 4), ('a', 2, 3), ('b', 1, 4), ('b', 2, 1), ('b', 3, 3)]
srs = rc.Series([1, 2, 3, 4, 5, 6], index=tuples)
print(srs)
    
    
The select_index method works with tuples by allowing the * to act as a wild card for matching.
In [48]:
    
compare = ('a', None, None)
srs.select_index(compare)
    
    Out[48]:
In [49]:
    
compare = ('a', None, 3)
srs.select_index(compare, 'boolean')
    
    Out[49]:
In [50]:
    
compare = (None, 2, None)
srs.select_index(compare, 'value')
    
    Out[50]:
In [51]:
    
compare = (None, None, 3)
srs.select_index(compare, 'value')
    
    Out[51]:
In [52]:
    
compare = (None, None, None)
srs.select_index(compare)
    
    Out[52]:
In [53]:
    
srs = rc.Series([1, 2, 3], index=[9, 10, 11])
print(srs)
    
    
In [54]:
    
srs.reset_index()
srs
    
    Out[54]:
In [55]:
    
srs = rc.Series([1, 2, 3], index=[9, 10, 11], index_name='new name')
print(srs)
    
    
In [56]:
    
srs.reset_index()
print(srs)
    
    
In [57]:
    
srs = rc.Series([3, 5, 4], index=[12, 15, 14], sort=True)
    
When sorted=True on initialization the data will be sorted by index to start
In [58]:
    
srs.print()
    
    
In [59]:
    
srs[16] = 9
print(srs)
    
    
In [60]:
    
srs.set(indexes=13, values=3.5)
print(srs)