In [1]:
import pandas as pd
In [7]:
import random
Create your own version of the Mayoral Excuse Machine in Python that takes in a name and location, selects an excuse at random and prints an excuse (“Sorry, Richard, I was late to City Hall to meet you, I had a very rough night and woke up sluggish”) Use the “excuses.csv” in the Github repository Extra credit if you print the link to the story as well
In [3]:
df=pd.read_csv('excuse.csv')
In [4]:
df.head(5)
Out[4]:
In [16]:
df = pd.read_csv('excuse.csv')
exe = random.choice(df['excuse'])
hl= df[df['excuse'] == exe ]['hyperlink']
hl
Out[16]:
In [6]:
name=input("What's your name? ")
location=input("What's your location? ")
In [25]:
def excuse(item):
df = pd.read_csv('excuse.csv')
exe = random.choice(df['excuse'])
hl= df[df['excuse'] == exe ]['hyperlink'].iloc[0]#how to get element from pandas series:.iloc
output= ("Sorry " + name + ", I was late to " + location +
" to meet you, " + exe + "." +hl)
return(output)
In [26]:
excuse(1)
Out[26]:
In [ ]: