In [39]:
%pylab inline
import pandas as pd
import os
from IPython.display import display
from IPython.html.widgets import interact_manual, interact
from random import choice
'''
 店名,距離,價位
stores_lst = [['牛肉麵','中','中'],
              ['燉肉飯','中','低'],
              ['壽司', '中', '高'],
stores_df = pd.DataFrame(stores_lst, columns=["店名","距離","價位"])
'''

areas = [file for file in os.listdir() if file[-4:] == '.csv']
try:
    stores_df = pd.read_csv(areas[0], encoding ='utf8')
except UnicodeDecodeError:
    stores_df = pd.read_csv(areas[0], encoding ='big5')   
        
def 選擇菜單(area):
    global stores_df
    print (area)
    try:
        stores_df = pd.read_csv(area, encoding ='utf8')
    except UnicodeDecodeError:
        stores_df = pd.read_csv(area, encoding ='big5')
    
def 上帝選吧():
    print (choice(stores_df["店名"]))  
    
def 三選一吧():
    tmp_df = stores_df
    c1 = choice(tmp_df["店名"])
    print (c1)
    tmp_df = tmp_df[tmp_df["店名"] != c1]
    tmp_df.index = range(0,len(tmp_df))
    #print (tmp_df)
    c2 = choice(tmp_df["店名"])
    print (c2)
    tmp_df = tmp_df[tmp_df["店名"] != c2]
    tmp_df.index = range(0,len(tmp_df))
    #print (tmp_df)
    c3 = choice(tmp_df["店名"])
    print (c3)
    #tmp_df = tmp_df[tmp_df["店名"] != c3]
    #print (tmp_df)  
    
def choose_by_distance(distance):
    '''
    distance: 遠, 中, 近
    '''
    gp = stores_df.groupby("距離")
    new_df = gp.get_group(name=distance)
    new_df.index = range(0,len(new_df))
    print (choice(new_df["店名"]))

def 近一點():
    choose_by_distance('近')
    
def 不近不遠():
    choose_by_distance('中')
    
def 遠一點():
    choose_by_distance('遠')

def choose_by_price(price):
    '''
    price: 高, 中, 低
    '''
    gp = stores_df.groupby("價位")
    new_df = gp.get_group(name=price)
    new_df.index = range(0,len(new_df))
    print (choice(new_df["店名"]))

def 便宜一點():
    choose_by_price('低')

def 價位適中():
    choose_by_price('中')
    
def 貴一點():
    choose_by_price('高')

def 給我選():
    display(stores_df)

interact(選擇菜單, area=areas);
interact_manual(上帝選吧);
interact_manual(三選一吧);
interact_manual(近一點);
interact_manual(不近不遠);
interact_manual(遠一點);
interact_manual(便宜一點);
interact_manual(價位適中);
interact_manual(貴一點);
interact_manual(給我選);


品果品果
Big MaMa
港園牛肉麵

In [3]:
help(choice)


Help on method choice in module random:

choice(seq) method of random.Random instance
    Choose a random element from a non-empty sequence.


In [35]:



樂卡麵
          店名 距離 價位
0      港園牛肉麵  中  高
1     小西門燉肉飯  中  中
2       松田壽司  中  高
3      阿進切仔麵  中  低
4      尚芳土魠魚  遠  中
5      阿英排骨飯  遠  中
6   Big MaMa  近  高
7       林爸廚房  近  中
9        豬腳麵  中  低
10      老師的麵  近  中
11      愛上乾麵  遠  中
12      品果品果  中  中
尚芳土魠魚
          店名 距離 價位
0      港園牛肉麵  中  高
1     小西門燉肉飯  中  中
2       松田壽司  中  高
3      阿進切仔麵  中  低
5      阿英排骨飯  遠  中
6   Big MaMa  近  高
7       林爸廚房  近  中
9        豬腳麵  中  低
10      老師的麵  近  中
11      愛上乾麵  遠  中
12      品果品果  中  中
港園牛肉麵
          店名 距離 價位
1     小西門燉肉飯  中  中
2       松田壽司  中  高
3      阿進切仔麵  中  低
5      阿英排骨飯  遠  中
6   Big MaMa  近  高
7       林爸廚房  近  中
9        豬腳麵  中  低
10      老師的麵  近  中
11      愛上乾麵  遠  中
12      品果品果  中  中

In [30]:
help(pd.core.frame.DataFrame.filter)


Help on function filter in module pandas.core.generic:

filter(self, items=None, like=None, regex=None, axis=None)
    Restrict the info axis to set of items or wildcard
    
    Parameters
    ----------
    items : list-like
        List of info axis to restrict to (must not all be present)
    like : string
        Keep info axis where "arg in col == True"
    regex : string (regular expression)
        Keep info axis with re.search(regex, col) == True
    axis : int or None
        The axis to filter on. By default this is the info axis. The "info
        axis" is the axis that is used when indexing with ``[]``. For
        example, ``df = DataFrame({'a': [1, 2, 3, 4]]}); df['a']``. So,
        the ``DataFrame`` columns are the info axis.
    
    Notes
    -----
    Arguments are mutually exclusive, but this is not checked for


In [ ]: