Basics Flashcards

1
Q

How do you import a CSV and convert it to a list of lists?

A

opened_file = open (“hacker_news.csv”)
from csv import reader
read_file = reader(opened_file)
hn= list(read_file)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you display the first five rows of a list of lists which name is “hn”?

A

print(hn[:5])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you import reader?

A

from csv import reader

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you import a CSV file?

A

opened_file= open(“AppleStore.csv”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you round a variable called “variable_a”?

A

round(variable_a)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

row_1 = [‘Facebook’, 0.0, ‘USD’, 2974676, 3.5]

Assign the fourth element from the list row_1 to a variable named ratings_1.

A

ratings_1 = (row_1[3])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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]

A

rating_1 = (row_1[-1])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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])
A

total_rating = (rating_1 + rating_2 +rating_3)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Display the lenght of a list of lists called apps_data

A

print(len(apps_data))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Display the header row of a list of lists called apps_data

A

print(apps_data[0])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

First four elements of the following list:

row_1 = [‘Facebook’, 0.0, ‘USD’, 2974676, 3.5]

A

row_1[:4]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Last 3 elements of the following list:

row_1 = [‘Facebook’, 0.0, ‘USD’, 2974676, 3.5]

A

row_1[-3:]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Select the list slice [‘USD’, 1126879] from the following list:

row_5 = [‘Pandora - Music & Radio’, 0.0, ‘USD’, 1126879, 4.0]

A

row_5[2:4]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the first step when converting a CSV into a lists of lists?

A

opened_file = open (“hacker_news.csv”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the second step when converting a CSV into a list of lists?

A

read_file = reader(opened_file)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the last step when converting a CSV into a list o lists?

A

hn= list(read_file)

17
Q

Create a list of lists with the following:

row_1 = ['Facebook', 0.0, 'USD', 2974676, 3.5]
row_2 = ['Instagram', 0.0, 'USD', 2161558, 4.5]
row_3 = ['Clash of Clans', 0.0, 'USD', 2130805, 4.5]
row_4 = ['Temple Run', 0.0, 'USD', 1724546, 4.5]
row_5 = ['Pandora - Music & Radio', 0.0, 'USD', 1126879, 4.0]
A

app_data_set = [row_1, row_2, row_3, row_4, row_5]

18
Q

From apps_data_set select row_1 and its last element and name it fb_rating.

row_1 = ['Facebook', 0.0, 'USD', 2974676, 3.5]
row_2 = ['Instagram', 0.0, 'USD', 2161558, 4.5]
row_3 = ['Clash of Clans', 0.0, 'USD', 2130805, 4.5]
row_4 = ['Temple Run', 0.0, 'USD', 1724546, 4.5]
row_5 = ['Pandora - Music & Radio', 0.0, 'USD', 1126879, 4.0]

app_data_set = [row_1, row_2, row_3, row_4, row_5]

A

fb_rating = app_data_set[0][4]

19
Q

From apps_data_set select row_4 and its last element and name it TR_rating.

row_1 = ['Facebook', 0.0, 'USD', 2974676, 3.5]
row_2 = ['Instagram', 0.0, 'USD', 2161558, 4.5]
row_3 = ['Clash of Clans', 0.0, 'USD', 2130805, 4.5]
row_4 = ['Temple Run', 0.0, 'USD', 1724546, 4.5]
row_5 = ['Pandora - Music & Radio', 0.0, 'USD', 1126879, 4.0]

app_data_set = [row_1, row_2, row_3, row_4, row_5]

A

TR_rating =app_data_set[3][4]

20
Q

What is the first line when starting a new loop on app_data_set?

A

for element in app_data_set:

21
Q

Assign the headers of data set hn to a varable called headers

A

headers = hn[0]

22
Q

Display a blank space

A

print(‘\n’)

23
Q

Remove the header row from a data set called hn

A

hn= hn[1:]