python Flashcards

1
Q

What line of code converts a Panda module Series to a Python list?

A

(ds.tolist())

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

What does the input code of a dictionary look like?

A

d1 = {‘a’: 100, ‘b’: 200, ‘c’:300, ‘d’:400, ‘e’:800}

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

How do you convert a pd.Series into a numpy array?

A

pd.Series(np_array)

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

What line of code changes the data type of given a column or a Series?

A

s2 = pd.to_numeric(s1, errors=’coerce’)

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

What line of code moves data in to a DataFrame?

A

df = pd.DataFrame(data=d)

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

What does the input code for data look like?

A

d = {‘col1’: [1, 2, 3, 4, 7, 11], ‘col2’: [4, 5, 6, 9, 5, 0], ‘col3’: [7, 5, 8, 12, 1,11]}

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

What line of code converts the first column of a DataFrame as a Series?

A

s1 = df.icol[:,0]

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

What line of code converts a given Series to an array?

A

a = s1.values

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

What does the input code for a series of lists look like?

A

s = pd.Series([
[‘Red’, ‘Green’, ‘White’],
[‘Red’, ‘Black’],
[‘Yellow’]])

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

What line of code converts Series of lists to one Series?

A

s = s.apply(pd.Series).stack().reset_index(drop=True)

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

What line of code sorts a given Series?

A

new_s = pd.Series(s).sort_values()

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

What line of code allows you to add some data to an existing Series?

A

new_s = pd.concat([s, pd.Series([500, “php”])], ignore_index=True)

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

What lines of code create a subset of a given series based on value and condition?

A

n = 6
new_s = s[s < n]

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

What lines of code change the order of index of a given series

A

s = pd.Series(data = [1,2,3,4,5], index = [‘A’, ‘B’, ‘C’,’D’,’E’])

s = s.reindex(index = [‘B’,’A’,’C’,’D’,’E’])

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

How would you create a mean and standard deviation for the data of a given Series?

A

print(s.mean())
print(s.std())

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

How do you print the first and last 5 columns of a dataset?

A

print(df.head(5))
print(df.tail(5))

17
Q

Python Pandas printing most costly car name

A

df = df [[‘company’,’price’]][df.price==df[‘price’].max()]