Skip to content

Introduction to Data Science in Python

Run the hidden code cell below to import the data used in this course.


1 hidden cell

Take Notes

Add notes about the concepts you've learned and code cells with code you want to keep.

Load the CSV "credit_records.csv"

credit_records = pd.read_csv("credit_records.csv")

Display the first five rows of credit_records using the .head() method

print(credit_records.head())

Select the location column in credit_records

location = credit_records['location']

Select the item column in credit_records

items = credit_records.item

Select the dogs whose Status is equal to Still Missing

still_missing = mpr[mpr.Status == "Still Missing"] print(still_missing)

Select all dogs whose Dog Breed is not equal to Poodle

not_poodle = mpr[mpr['Dog Breed'] != "Poodle"] print(not_poodle)

From matplotlib, import pyplot under the alias plt

from matplotlib import pyplot as plt

Plot Officer Deshaun's hours_worked vs. day_of_week

plt.plot(deshaun.day_of_week, deshaun.hours_worked)

Display Deshaun's plot

plt.show()

Add a label to Mengfei's plot

plt.plot(mengfei.day_of_week, mengfei.hours_worked, label='Mengfei')

Add a command to make the legend display

plt.legend()

Add a title

plt.title("descriptive")

Add y-axis label

plt.ylabel("hours worked")

Add annotation "Missing June data" at (2.5, 80)

plt.text(2.5, 80, "Missing June data")

Change the color of Phoenix to "DarkCyan"

plt.plot(data["Year"], data["Phoenix Police Dept"], label="Phoenix", color = "DarkCyan")

Make the Los Angeles line dotted

plt.plot(data["Year"], data["Los Angeles Police Dept"], label="Los Angeles", linestyle=":")

Add square markers to Philedelphia

plt.plot(data["Year"], data["Philadelphia Police Dept"], label="Philadelphia", marker="s")

Change the style to fivethirtyeight

plt.style.use("fivethirtyeight")

Create a scatter plot of the data from the DataFrame cellphone

plt.scatter(cellphone.x, cellphone.y)

Create a bar plot from the DataFrame hours

plt.bar(hours.officer, hours.avg_hours_worked, # Add error bars yerr=hours.std_hours_worked)

Plot the hours spent on field work on top of desk work

plt.bar(hours.officer, hours.field_work, bottom=hours.desk_work, label='Field Work')

Create a histogram of the column weight from the DataFrame puppies

plt.hist(puppies.weight)

Create a histogram

Range is 2 to 8, with 40 bins

plt.hist(gravel.radius, range=(2,8), bins=40)

Create a histogram

Normalize to 1

plt.hist(gravel.radius, bins=40, range=(2, 8), density = 1)

my_house greater than 18.5 or smaller than 10

print(np.logical_or(my_house>18.5, my_house<10))

Both my_house and your_house smaller than 11

print(np.logical_and(my_house<11, your_house<11))

# Add your code snippets here