Pandas/Python Flashcards

1
Q

What will the following two slicers return?
1. “owl”[0:2]
2. “hello”[3:]

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

What is returned by the following statements?

myveg = [‘lettuce’,’celery’,’carrot’]
myveg[1]

A

celery

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

myveg = [‘lettuce’,’celery’,’carrot’]

Which has the correct syntax to print each element in the list?

A

for veg in myveg: print(veg)

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

Which statement will add “cauliflower” to the list myveg?

A

myveg.apend(“cauliflower”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. What Python data type should you use to store key-value pairs?
  2. What Python data type should you use to an ordered sequence of values?
A
  1. dictionary
  2. list
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which statement will add a new item “mykey” with a value of 3 to the dictionary “mydict”?

A

mydict[“mykey”] = 3

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

What data type is returned by the following statements: import pandas as pd pd.read_csv(“example1.csv”)

A

series

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

For pandas variable pd, write a statement that will read from data.txt, a piple delimited file.

A

pd.read_csv(‘data.txt’, delim=’|’

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

You have a dataframe called df. Which statement will return the first five rows of the dataframe?

A

df.head()

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

You have a dataframe called df. Which statement will provide some descriptive statistics about the numeric columns in the dataframe?

A

df.describe()

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

You have a dataframe called “chipo” with a column “quantity”. Which statement will give you the quality column as a series?

A

chipo[“quality”]

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

What is the OR operator in Python? In Pandas?

A

Python: OR
Pandas: |

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

You have a dataframe “chipo” with a column called order_id. How can you sort so that the highest value of order_id is shown first, with lower values following?

A

chipo.sort_values(by=”order_id”,ascending=False)

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

You have a dataframe called miles_per_gallon that lists the car models, their mpg, and origin. Write a panda statement to select the mpg field grouped by origin and ordered by mpg in descending order.

A

miles_per_gallon.groupby(by=”origin”)[“mpg”].mean().sort_values(ascending=False)

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

You have a dataframe called miles_per_gallon that lists the car models, their mpg, and origin. Write a panda statement to select the 50 records with the lowes mpg values

A

miles_per_gallon.sort_values(by=’mpg’, ascending=True).head(50)

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

filter your data frame DF to only contain records where the Job field is “admin”

A

new_df = df[df[“job”] == “admin”]

17
Q

filter your data frame DF to only contain records where the marital column is “married” and the job column is “blue-collar”

A

marriedblue = df[(df[“marital”] == “married”) & (df[“job”] == “blue-collar”)]

18
Q

filter your data frame DF to only contain records where the marital column is null

A

nullrecord = df[df[“marital”].isnull() ]

19
Q

What’s the correct syntax for creating a scatter plot in matplotlib?

A

plt.scatter(x_data, y_data) or
plt.scatter(x_data, y_data, marker=”o”)

20
Q

What is hash table collision and how do you prevent it from happening

A

[A hash table is a data structure that implements an associative array (ie dictionary) mapping keys to values.]

A hash table collision is the term used to describe a scenario when two or more keys point to the same value.

Some ways to prevent, or significantly minimize, a collision including increasing the size of the table, using a stronger algorithm for your values, and using chaining, or a technique where multiple items that hash to the same location are stored together in a linked list or chain.

21
Q
A