_This is a quiz given in Roger Peng Coursera class Computing for Data Analysis. _
Sourced from Research Computing MeetUp's Python course.
import pandas as pd
import os
data = pd.read_csv(os.path.join('data', 'ozone.csv'))
print data.head()
Ozone Solar.R Wind Temp Month Day 0 41 190 7.4 67 5 1 1 36 118 8.0 72 5 2 2 12 149 12.6 74 5 3 3 18 313 11.5 62 5 4 4 NaN NaN 14.3 56 5 5
Print the column names of the dataset to the screen, one column name per line.
Extract the first 2 rows of the data frame and print them to the console. What does the output look like?
How many observations (i.e. rows) are in this data frame?
Extract the last 2 rows of the data frame and print them to the console. What does the output look like?
What is the value of Ozone in the 47th row?
How many missing values are in the Ozone column of this data frame?
What is the mean of the Ozone column in this dataset? Exclude missing values (coded as NA) from this calculation.
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?
What is the mean of "Temp" when "Month" is equal to 6?
What was the maximum ozone value in the month of May (i.e. Month = 5)?
Kaggle has a nice challenge based on titanic passenger data:
"One of the reasons that the shipwreck led to such loss of life was that there were not enough lifeboats for the passengers and crew. Although there was some element of luck involved in surviving the sinking, some groups of people were more likely to survive than others, such as women, children, and the upper-class."
We'll use the 892 line training set from Kaggle, located in the data directory of this lesson.
import os
import pandas as pd
a=pd.read_csv('./data/titanic.csv')
pandas.read_csv
891
linesd.survived == 1
Write a function that returns a dictionary of the number of survived
, not survived
, and unknown
. Here is the example function call:
print titanic_function(data)
{'survived': 342, 'not survived': 549}
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 |