import statsmodels as sm
import seaborn as sns
import numpy as np
Introduction to Data Science in Python
Importing Python modules
Modules (sometimes called packages or libraries) help group together related sets of tools in Python. In this exercise, we’ll examine two modules that are frequently used by Data Scientists:
statsmodels: used in machine learning; usually aliased as sm seaborn: a visualization library; usually aliased as sns Note that each module has a standard alias, which allows you to access the tools inside of the module without typing as many characters. For example, aliasing lets us shorten seaborn.scatterplot() to sns.scatterplot().
Creating a float
Before we start looking for Bayes’ kidnapper, we need to fill out a Missing Puppy Report with details of the case. Each piece of information will be stored as a variable.
We define a variable using an equals sign (=). For instance, we would define the variable height:
height = 24 In this exercise, we’ll be defining bayes_age to be 4.0 months old. The data type for this variable will be float, meaning that it is a number.
= 4.0
bayes_age bayes_age
4.0
Creating strings
Let’s continue to fill out the Missing Puppy Report for Bayes. In the previous exercise, we defined bayes_age, which was a float, which represents a number.
In this exercise, we’ll define favorite_toy and owner, which will both be strings. A string represents text. A string is surrounded by quotation marks (’ or “) and can contain letters, numbers, and special characters. It doesn’t matter if you use single (’) or double (”) quotes, but it’s important to be consistent throughout your code.
= "Mr. Squeaky"
favorite_toy = "DataCamp"
owner # Display variables
print(favorite_toy)
print(owner)
Mr. Squeaky
DataCamp
Correcting string errors
It’s easy to make errors when you’re trying to type strings quickly.
Don’t forget to use quotes! Without quotes, you’ll get a name error. owner = DataCamp Use the same type of quotation mark. If you start with a single quote, and end with a double quote, you’ll get a syntax error. fur_color = “blonde’ Someone at the police station made an error when filling out the final lines of Bayes’ Missing Puppy Report. In this exercise, you will correct the errors.
# One or more of the following lines contains an error
# Correct it so that it runs without producing syntax errors
= '2017-07-14'
birthday = 'DATACAMP!123-456?' case_id