-
-
Save codecademydev/eaaaae86581386b46ced22763b8775f2 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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