Pandas/Python Flashcards
What will the following two slicers return?
1. “owl”[0:2]
2. “hello”[3:]
- ow
- lo
What is returned by the following statements?
myveg = [‘lettuce’,’celery’,’carrot’]
myveg[1]
celery
myveg = [‘lettuce’,’celery’,’carrot’]
Which has the correct syntax to print each element in the list?
for veg in myveg: print(veg)
Which statement will add “cauliflower” to the list myveg?
myveg.apend(“cauliflower”)
- What Python data type should you use to store key-value pairs?
- What Python data type should you use to an ordered sequence of values?
- dictionary
- list
Which statement will add a new item “mykey” with a value of 3 to the dictionary “mydict”?
mydict[“mykey”] = 3
What data type is returned by the following statements: import pandas as pd pd.read_csv(“example1.csv”)
series
For pandas variable pd, write a statement that will read from data.txt, a piple delimited file.
pd.read_csv(‘data.txt’, delim=’|’
You have a dataframe called df. Which statement will return the first five rows of the dataframe?
df.head()
You have a dataframe called df. Which statement will provide some descriptive statistics about the numeric columns in the dataframe?
df.describe()
You have a dataframe called “chipo” with a column “quantity”. Which statement will give you the quality column as a series?
chipo[“quality”]
What is the OR operator in Python? In Pandas?
Python: OR
Pandas: |
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?
chipo.sort_values(by=”order_id”,ascending=False)
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.
miles_per_gallon.groupby(by=”origin”)[“mpg”].mean().sort_values(ascending=False)
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
miles_per_gallon.sort_values(by=’mpg’, ascending=True).head(50)