Basics Flashcards
How do you import a CSV and convert it to a list of lists?
opened_file = open (“hacker_news.csv”)
from csv import reader
read_file = reader(opened_file)
hn= list(read_file)
How do you display the first five rows of a list of lists which name is “hn”?
print(hn[:5])
How do you import reader?
from csv import reader
How do you import a CSV file?
opened_file= open(“AppleStore.csv”)
How do you round a variable called “variable_a”?
round(variable_a)
row_1 = [‘Facebook’, 0.0, ‘USD’, 2974676, 3.5]
Assign the fourth element from the list row_1 to a variable named ratings_1.
ratings_1 = (row_1[3])
Assign the last element from the list row_1 to a variable named rating_1. Try to take advantage of negative indexing
row_1 = [‘Facebook’, 0.0, ‘USD’, 2974676, 3.5]
rating_1 = (row_1[-1])
Add the three ratings together and save the sum to a variable named total_rating
rating_1 = (row_1[-1]) rating_2 = (row_2[-1]) rating_3 = (row_3[-1])
total_rating = (rating_1 + rating_2 +rating_3)
Display the lenght of a list of lists called apps_data
print(len(apps_data))
Display the header row of a list of lists called apps_data
print(apps_data[0])
First four elements of the following list:
row_1 = [‘Facebook’, 0.0, ‘USD’, 2974676, 3.5]
row_1[:4]
Last 3 elements of the following list:
row_1 = [‘Facebook’, 0.0, ‘USD’, 2974676, 3.5]
row_1[-3:]
Select the list slice [‘USD’, 1126879] from the following list:
row_5 = [‘Pandora - Music & Radio’, 0.0, ‘USD’, 1126879, 4.0]
row_5[2:4]
What is the first step when converting a CSV into a lists of lists?
opened_file = open (“hacker_news.csv”)
What is the second step when converting a CSV into a list of lists?
read_file = reader(opened_file)