This is a quiz given in Roger Peng's Coursera class Computing for Data Analysis.
Sourced from Research Computing MeetUp's Python course.
In [10]:
import pandas as pd
import numpy as np
import os
path = ""
data = pd.read_csv("https://github.com/JamesByers/GA-SEA-DAT2/raw/master/data/ozone.csv")
In [11]:
print data.head()
Print the column names of the dataset to the screen, one column name per line.
In [43]:
data.columns
Out[43]:
Extract the first 2 rows of the data frame and print them to the console. Console in this case is output into the jupyter notebook. What does the output look like?
In [4]:
print data.head(2)
How many observations (i.e. rows) are in this data frame?
In [9]:
print data.count()
Extract the last 2 rows of the data frame and print them to the console. What does the output look like?
In [10]:
print data.tail(2)
What is the value of Ozone in the 47th row?
In [15]:
print data.loc[47:47,['Ozone']]
How many missing values are in the Ozone column of this data frame?
In [17]:
pd.isnull(data['Ozone']).sum()
#print misscnt
#cnt = data['Ozone'].count()
#print cnt
#np.count_nonzero(np.eye(4))
#cnt1 = np.count_nonzero(pd.isnull(data['Ozone']).values)
#np.count_nonzero(df.isnull())
#print cnt1
Out[17]:
In [18]:
cnt = data['Ozone'] == np.nan
print cnt.count()
What is the mean of the Ozone column in this dataset? Exclude missing values (coded as NA) from this calculation.
In [19]:
data['Ozone'].mean()
Out[19]:
Extract the subset of rows of the data frame where Ozone values are above 31 and Temp values are above 90. What is the mean of Solar.R in this subset?
In [34]:
#df_posA[df_posA.A < 0] = -1*df_posA
newdf = data[(data.Ozone> 31 )& (data.Temp >90)]
newdf.mean()
Out[34]:
What is the mean of "Temp" when "Month" is equal to 6?
In [ ]:
What was the maximum ozone value in the month of May (i.e. Month = 5)?
In [ ]:
Recommended Resources
| Name | Description |
|---|---|
| Official Pandas Tutorials | Wes & Company's selection of tutorials and lectures |
| Julia Evans Pandas Cookbook | Great resource with eamples from weather, bikes and 311 calls |
| Learn Pandas Tutorials | A great series of Pandas tutorials from Dave Rojas |
| Research Computing Python Data PYNBs | A super awesome set of python notebooks from a meetup-based course exclusively devoted to pandas |