Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created May 1, 2020 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/eaaaae86581386b46ced22763b8775f2 to your computer and use it in GitHub Desktop.
Save codecademydev/eaaaae86581386b46ced22763b8775f2 to your computer and use it in GitHub Desktop.
Codecademy export
import pandas as pd
pd.set_option('display.max_colwidth', -1)
df=pd.read_csv("jeopardy.csv")
#print(df)
df.rename(columns={
' Air Date': 'Air Date',
' Round': 'Round',
' Category': 'Category',
' Value': 'Value',
' Question': 'Question',
' Answer': 'Answer'
}, inplace=True)
print(df.head())
#function that will tell us if the row[question] contains every single item from the list passed
def true_or_false(row_question, lst):
array=[]
for element in lst:
if element.isin(row_question):
array.append(True)
else:
array.append(True)
return all(array)
#lambda function to select all the rows that match the conditions
lst=['King',"England"]
filtered_data=df.apply(lambda row: row if true_or_false(row['Question'],lst), axis=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment