In [77]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import c
%matplotlib inline

In [5]:
from plotly.offline import download_plotlyjs, init_notebook_mode, plot
from plotly.graph_objs import *
init_notebook_mode()


file = "./Playdata.xlsx"
#df = pd.read_excel(file, sheetname = 'Sheet1', header = 0, index_col = 0, convert_float = True)
#dv = pd.read_excel(file, sheetname = 'Sheet3', header = 0, index_col = 0, convert_float = True)
df = pd.read_excel(file, sheetname = 'Sheet1', header = 0, convert_float = True)
dv = pd.read_excel(file, sheetname = 'Sheet3', header = 0, index_col = 0, convert_float = True)

df['protein_percent'] = df['protein']/dv['DV']['Protein'] *100
df['totalcal'] = df['calperserv']/dv['DV']['Caloriesm'] * 100
df['foodtext'] = "\nCalories : " + str(df['calperserv']) + "\nProtein : " + str(df['protein'])



In [8]:
foodgrp_key= list(set(df['foodgroup']))
grp_val = list(map(int,range(len(foodgrp_key))))
grpdict = dict(zip(foodgrp_key,grp_val))

#for i in df["foodgroup"]:
  # df["grpnumbers"] = grphash[df["foodgroup"][i]]

In [11]:
grpdict


Out[11]:
{'Bread': 2,
 'Burger': 7,
 'Candy': 0,
 'Dessert': 8,
 'Dressing': 3,
 'Fruit': 1,
 'Meat': 4,
 'Pasta': 9,
 'Pizza': 11,
 'Spread': 6,
 'Vegetable': 10,
 'fruit': 5}

In [37]:
grpdict["Burger"]


Out[37]:
7

In [67]:
converter = {}
i=1
for item in df["foodgroup"]:
    if item not in converter:
        converter[item] =i
        i += 1
df['foodgrpnum'] = [converter[i] for i in df["foodgroup"]]

In [76]:
df['foodgrpnum']#df['foodgrpnum'] = df.apply(lambda row: [v for k, v in new_data.items() if row['foodgroup'] == k][0], axis = 1)


Out[76]:
0      1
1      1
2      1
3      1
4      2
5      3
6      3
7      4
8      5
9      6
10     7
11     8
12     4
13     5
14     9
15     2
16     2
17     1
18    10
19    11
20    10
21     3
22     3
23     3
24     1
25    12
Name: foodgrpnum, dtype: int64

In [73]:
plot({
    'data': [
        Scatter(x=df['calperserv'],
                y=df['score'],
                text=df['foodtext'],
                #marker=Marker(size=df['calperserv'], sizemode='area'),   #, sizeref=131868,),
                marker = dict(size= 14,
                    line= dict(width=1),
                    color= c[i],
                    opacity= 0.3
                   ),name= y[i],
                mode='markers',
               ) 
    ],
    'layout': Layout(title='Nutrition and Calorie Count',xaxis=XAxis(title='Calories per Serving'), yaxis=YAxis(title='Nutrition 1-10'),
                    hovermode = closest)
}, show_link=False)


Out[73]:
'file://C:\\Users\\Art\\Documents\\Python Workspace\\foodfilter\\temp-plot.html'

In [57]:
type(df[['foodgrpnum']])


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
C:\Program Files\Anaconda3\lib\site-packages\pandas\indexes\base.py in get_loc(self, key, method, tolerance)
   2133             try:
-> 2134                 return self._engine.get_loc(key)
   2135             except KeyError:

pandas\index.pyx in pandas.index.IndexEngine.get_loc (pandas\index.c:4443)()

pandas\index.pyx in pandas.index.IndexEngine.get_loc (pandas\index.c:4289)()

pandas\src\hashtable_class_helper.pxi in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:13733)()

pandas\src\hashtable_class_helper.pxi in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:13687)()

KeyError: 5

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
<ipython-input-57-a159d58e189b> in <module>()
----> 1 type(df[['foodgrpnum']][5])
      2 
      3 

C:\Program Files\Anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
   2057             return self._getitem_multilevel(key)
   2058         else:
-> 2059             return self._getitem_column(key)
   2060 
   2061     def _getitem_column(self, key):

C:\Program Files\Anaconda3\lib\site-packages\pandas\core\frame.py in _getitem_column(self, key)
   2064         # get column
   2065         if self.columns.is_unique:
-> 2066             return self._get_item_cache(key)
   2067 
   2068         # duplicate columns & possible reduce dimensionality

C:\Program Files\Anaconda3\lib\site-packages\pandas\core\generic.py in _get_item_cache(self, item)
   1384         res = cache.get(item)
   1385         if res is None:
-> 1386             values = self._data.get(item)
   1387             res = self._box_item_values(item, values)
   1388             cache[item] = res

C:\Program Files\Anaconda3\lib\site-packages\pandas\core\internals.py in get(self, item, fastpath)
   3539 
   3540             if not isnull(item):
-> 3541                 loc = self.items.get_loc(item)
   3542             else:
   3543                 indexer = np.arange(len(self.items))[isnull(self.items)]

C:\Program Files\Anaconda3\lib\site-packages\pandas\indexes\base.py in get_loc(self, key, method, tolerance)
   2134                 return self._engine.get_loc(key)
   2135             except KeyError:
-> 2136                 return self._engine.get_loc(self._maybe_cast_indexer(key))
   2137 
   2138         indexer = self.get_indexer([key], method=method, tolerance=tolerance)

pandas\index.pyx in pandas.index.IndexEngine.get_loc (pandas\index.c:4443)()

pandas\index.pyx in pandas.index.IndexEngine.get_loc (pandas\index.c:4289)()

pandas\src\hashtable_class_helper.pxi in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:13733)()

pandas\src\hashtable_class_helper.pxi in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:13687)()

KeyError: 5

In [75]:
N=53
c= ['hsl('+str(h)+',50%'+',50%)' for h in np.linspace(0, 360, N)]
c


Out[75]:
['hsl(0.0,50%,50%)',
 'hsl(6.92307692308,50%,50%)',
 'hsl(13.8461538462,50%,50%)',
 'hsl(20.7692307692,50%,50%)',
 'hsl(27.6923076923,50%,50%)',
 'hsl(34.6153846154,50%,50%)',
 'hsl(41.5384615385,50%,50%)',
 'hsl(48.4615384615,50%,50%)',
 'hsl(55.3846153846,50%,50%)',
 'hsl(62.3076923077,50%,50%)',
 'hsl(69.2307692308,50%,50%)',
 'hsl(76.1538461538,50%,50%)',
 'hsl(83.0769230769,50%,50%)',
 'hsl(90.0,50%,50%)',
 'hsl(96.9230769231,50%,50%)',
 'hsl(103.846153846,50%,50%)',
 'hsl(110.769230769,50%,50%)',
 'hsl(117.692307692,50%,50%)',
 'hsl(124.615384615,50%,50%)',
 'hsl(131.538461538,50%,50%)',
 'hsl(138.461538462,50%,50%)',
 'hsl(145.384615385,50%,50%)',
 'hsl(152.307692308,50%,50%)',
 'hsl(159.230769231,50%,50%)',
 'hsl(166.153846154,50%,50%)',
 'hsl(173.076923077,50%,50%)',
 'hsl(180.0,50%,50%)',
 'hsl(186.923076923,50%,50%)',
 'hsl(193.846153846,50%,50%)',
 'hsl(200.769230769,50%,50%)',
 'hsl(207.692307692,50%,50%)',
 'hsl(214.615384615,50%,50%)',
 'hsl(221.538461538,50%,50%)',
 'hsl(228.461538462,50%,50%)',
 'hsl(235.384615385,50%,50%)',
 'hsl(242.307692308,50%,50%)',
 'hsl(249.230769231,50%,50%)',
 'hsl(256.153846154,50%,50%)',
 'hsl(263.076923077,50%,50%)',
 'hsl(270.0,50%,50%)',
 'hsl(276.923076923,50%,50%)',
 'hsl(283.846153846,50%,50%)',
 'hsl(290.769230769,50%,50%)',
 'hsl(297.692307692,50%,50%)',
 'hsl(304.615384615,50%,50%)',
 'hsl(311.538461538,50%,50%)',
 'hsl(318.461538462,50%,50%)',
 'hsl(325.384615385,50%,50%)',
 'hsl(332.307692308,50%,50%)',
 'hsl(339.230769231,50%,50%)',
 'hsl(346.153846154,50%,50%)',
 'hsl(353.076923077,50%,50%)',
 'hsl(360.0,50%,50%)']

In [79]:
cl.scales['3']['div']['RdYlBu']))


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-79-74839918fd53> in <module>()
----> 1 HTML(cl.to_html(cl.scales['3']['div']['RdYlBu']))

NameError: name 'HTML' is not defined

In [ ]: