In [1]:
# import libraries
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
matplotlib.style.use('ggplot')
import random as rng
import numpy as np
%matplotlib inline

# take a url of the csv or can read the csv locally into a pandas data frame
data = pd.read_csv("robodummy.csv", index_col=0)

9 defenses

  1. Low Bar
  2. ALLIANCE selected
  3. Audience selected
  4. ALLIANCE selected
  5. ALLIANCE selected

Data structure choices include:

  • Pandas dataframes
  • Numpy Arrays
  • Object oriented
  • Dictionary

In [2]:
# Object oriented approach, would have to feed csv data into objects

# maybe get rid of this and just use library analysis tools
class Robot(object):

	def __init__(self, name, alliance, auto_points, points):

		self.name = name
		self.alliance = alliance
		self.auto_points = auto_points
		self.points = points

	def points_per_sec(self):
		return self.points / 150

	def auto_points_per_sec(self):
		return self.auto_points / 15

	def get_name(self):
		return self.name

	def get_alliance(self):
		return self.alliance

In [3]:
data


Out[3]:
Cougar Tech Webster PIttsford Rush Henrietta
Auto Points 10.00 15.0 5.0 20.00
Points 35.00 45.0 15.0 55.00
Low Bar 1.00 1.0 1.0 1.00
Portcullis 1.00 0.5 1.0 0.50
Cheval de Frise 1.00 1.0 1.0 0.75
Moat 0.25 1.0 1.0 0.30
Ramparts 0.50 1.0 0.3 0.50
Drawbridge 0.50 1.0 0.5 0.30
Sally Port 1.00 0.3 0.5 0.90
Rock Wall 0.75 0.7 0.9 0.50
Rough Terrain 0.30 0.5 0.9 1.00

In [4]:
def analyze(dataframe, team):
    total_points = dataframe[team]['Points'] + dataframe[team]['Auto Points']
    cumulative_success_rate = 4
    pps = dataframe[team]['Points'] / 150
    auto_pps = dataframe[team]['Auto Points'] / 15
    
    return(total_points, pps, auto_pps)

stuff = analyze(data, 'Cougar Tech')
print stuff


(45.0, 0.23333333333333334, 0.66666666666666663)

Analysis Functions:


In [5]:
data = pd.read_csv("robodummy.csv")
fig, axs = plt.subplots(1, 4, sharey = True)
data.plot(kind='scatter', x = 'x', y = 'y', ax = axs[0], figsize = (16, 8))
data.plot(kind='scatter', x = 'x', y = 'y', ax = axs[1])
data.plot(kind='scatter', x = 'x', y = 'y', ax = axs[2])


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-5-4ef5c3d9fa2f> in <module>()
      1 data = pd.read_csv("robodummy.csv")
      2 fig, axs = plt.subplots(1, 4, sharey = True)
----> 3 data.plot(kind='scatter', x = 'x', y = 'y', ax = axs[0], figsize = (16, 8))
      4 data.plot(kind='scatter', x = 'x', y = 'y', ax = axs[1])
      5 data.plot(kind='scatter', x = 'x', y = 'y', ax = axs[2])

/Users/dinbecevic/anaconda/lib/python2.7/site-packages/pandas/tools/plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
   3669                           fontsize=fontsize, colormap=colormap, table=table,
   3670                           yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671                           sort_columns=sort_columns, **kwds)
   3672     __call__.__doc__ = plot_frame.__doc__
   3673 

/Users/dinbecevic/anaconda/lib/python2.7/site-packages/pandas/tools/plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
   2554                  yerr=yerr, xerr=xerr,
   2555                  secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556                  **kwds)
   2557 
   2558 

/Users/dinbecevic/anaconda/lib/python2.7/site-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
   2382         plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
   2383 
-> 2384     plot_obj.generate()
   2385     plot_obj.draw()
   2386     return plot_obj.result

/Users/dinbecevic/anaconda/lib/python2.7/site-packages/pandas/tools/plotting.pyc in generate(self)
    985         self._compute_plot_data()
    986         self._setup_subplots()
--> 987         self._make_plot()
    988         self._add_table()
    989         self._make_legend()

/Users/dinbecevic/anaconda/lib/python2.7/site-packages/pandas/tools/plotting.pyc in _make_plot(self)
   1556         else:
   1557             label = None
-> 1558         scatter = ax.scatter(data[x].values, data[y].values, c=c_values,
   1559                              label=label, cmap=cmap, **self.kwds)
   1560         if cb:

/Users/dinbecevic/anaconda/lib/python2.7/site-packages/pandas/core/frame.pyc in __getitem__(self, key)
   1967             return self._getitem_multilevel(key)
   1968         else:
-> 1969             return self._getitem_column(key)
   1970 
   1971     def _getitem_column(self, key):

/Users/dinbecevic/anaconda/lib/python2.7/site-packages/pandas/core/frame.pyc in _getitem_column(self, key)
   1974         # get column
   1975         if self.columns.is_unique:
-> 1976             return self._get_item_cache(key)
   1977 
   1978         # duplicate columns & possible reduce dimensionality

/Users/dinbecevic/anaconda/lib/python2.7/site-packages/pandas/core/generic.pyc in _get_item_cache(self, item)
   1089         res = cache.get(item)
   1090         if res is None:
-> 1091             values = self._data.get(item)
   1092             res = self._box_item_values(item, values)
   1093             cache[item] = res

/Users/dinbecevic/anaconda/lib/python2.7/site-packages/pandas/core/internals.pyc in get(self, item, fastpath)
   3209 
   3210             if not isnull(item):
-> 3211                 loc = self.items.get_loc(item)
   3212             else:
   3213                 indexer = np.arange(len(self.items))[isnull(self.items)]

/Users/dinbecevic/anaconda/lib/python2.7/site-packages/pandas/core/index.pyc in get_loc(self, key, method, tolerance)
   1757                                  'backfill or nearest lookups')
   1758             key = _values_from_object(key)
-> 1759             return self._engine.get_loc(key)
   1760 
   1761         indexer = self.get_indexer([key], method=method,

pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:3979)()

pandas/index.pyx in pandas.index.IndexEngine.get_loc (pandas/index.c:3843)()

pandas/hashtable.pyx in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12265)()

pandas/hashtable.pyx in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12216)()

KeyError: 'x'

In [10]:
a = np.array(([1, 4], [6, 5], [9, 3]))
np.sort(a)


Out[10]:
array([[1, 4],
       [5, 6],
       [3, 9]])