Menu iconMenu iconData Analysis Foundations with Python
Data Analysis Foundations with Python

Chapter 1: Introduction to Data Analysis and Python

1.4 Practical Exercises for Chapter 1: Introduction to Data Analysis and Python

Exercise 1: Define a Data Analysis Problem

  • Objective: To exercise your ability to frame a problem suitable for data analysis.
  • Task: Write down a problem statement or question that you would like to solve using data analysis. Be as specific as possible.
  • Hint: Examples of problem statements could be "What is the average age of customers who purchased a particular product?" or "How do temperature changes affect electricity consumption?"

Exercise 2: Data Collection with Python

  • Objective: Familiarize yourself with Python's capabilities for data collection.
  • Task: Use Python's requests library to fetch data from an open API of your choice.
  • Hint: Make sure to check the API's documentation for usage guidelines.
# Starter Code
import requests

response = requests.get("<https://api.example.com/your_endpoint>")
print(response.json())

Exercise 3: Basic Data Cleaning with Pandas

  • Objective: To clean a simple dataset using Python's Pandas library.
  • Task: Import a CSV file into a Pandas DataFrame and replace all NaN (null) values with 0.
  • Hint: Use the fillna() method in Pandas.
# Starter Code
import pandas as pd

df = pd.read_csv("your_file.csv")
df.fillna(0, inplace=True)

Download here the your_file.csv file

Exercise 4: Create a Basic Plot

  • Objective: To practice creating a basic plot using Matplotlib.
  • Task: Plot a histogram of ages from the DataFrame you used in Exercise 3.
  • Hint: Use Matplotlib's hist() function.
# Starter Code
import matplotlib.pyplot as plt

plt.hist(df['age'], bins=20)
plt.show()

Exercise 5: Evaluate a Simple Model

  • Objective: To get a feel for basic model evaluation.
  • Task: Use the Scikit-learn library to fit a Linear Regression model on any two variables from the DataFrame you used in Exercise 3. Evaluate the model's performance using the Mean Squared Error (MSE) metric.
  • Hint: Use LinearRegression from Scikit-learn's linear_model module and mean_squared_error from the metrics module.
# Starter Code
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error

# Your code here

By working through these exercises, you'll solidify your understanding of the data analysis process and get hands-on experience with Python's data analysis libraries. Good luck, and remember: the key to mastering data analysis is practice, practice, practice!

1.4 Practical Exercises for Chapter 1: Introduction to Data Analysis and Python

Exercise 1: Define a Data Analysis Problem

  • Objective: To exercise your ability to frame a problem suitable for data analysis.
  • Task: Write down a problem statement or question that you would like to solve using data analysis. Be as specific as possible.
  • Hint: Examples of problem statements could be "What is the average age of customers who purchased a particular product?" or "How do temperature changes affect electricity consumption?"

Exercise 2: Data Collection with Python

  • Objective: Familiarize yourself with Python's capabilities for data collection.
  • Task: Use Python's requests library to fetch data from an open API of your choice.
  • Hint: Make sure to check the API's documentation for usage guidelines.
# Starter Code
import requests

response = requests.get("<https://api.example.com/your_endpoint>")
print(response.json())

Exercise 3: Basic Data Cleaning with Pandas

  • Objective: To clean a simple dataset using Python's Pandas library.
  • Task: Import a CSV file into a Pandas DataFrame and replace all NaN (null) values with 0.
  • Hint: Use the fillna() method in Pandas.
# Starter Code
import pandas as pd

df = pd.read_csv("your_file.csv")
df.fillna(0, inplace=True)

Download here the your_file.csv file

Exercise 4: Create a Basic Plot

  • Objective: To practice creating a basic plot using Matplotlib.
  • Task: Plot a histogram of ages from the DataFrame you used in Exercise 3.
  • Hint: Use Matplotlib's hist() function.
# Starter Code
import matplotlib.pyplot as plt

plt.hist(df['age'], bins=20)
plt.show()

Exercise 5: Evaluate a Simple Model

  • Objective: To get a feel for basic model evaluation.
  • Task: Use the Scikit-learn library to fit a Linear Regression model on any two variables from the DataFrame you used in Exercise 3. Evaluate the model's performance using the Mean Squared Error (MSE) metric.
  • Hint: Use LinearRegression from Scikit-learn's linear_model module and mean_squared_error from the metrics module.
# Starter Code
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error

# Your code here

By working through these exercises, you'll solidify your understanding of the data analysis process and get hands-on experience with Python's data analysis libraries. Good luck, and remember: the key to mastering data analysis is practice, practice, practice!

1.4 Practical Exercises for Chapter 1: Introduction to Data Analysis and Python

Exercise 1: Define a Data Analysis Problem

  • Objective: To exercise your ability to frame a problem suitable for data analysis.
  • Task: Write down a problem statement or question that you would like to solve using data analysis. Be as specific as possible.
  • Hint: Examples of problem statements could be "What is the average age of customers who purchased a particular product?" or "How do temperature changes affect electricity consumption?"

Exercise 2: Data Collection with Python

  • Objective: Familiarize yourself with Python's capabilities for data collection.
  • Task: Use Python's requests library to fetch data from an open API of your choice.
  • Hint: Make sure to check the API's documentation for usage guidelines.
# Starter Code
import requests

response = requests.get("<https://api.example.com/your_endpoint>")
print(response.json())

Exercise 3: Basic Data Cleaning with Pandas

  • Objective: To clean a simple dataset using Python's Pandas library.
  • Task: Import a CSV file into a Pandas DataFrame and replace all NaN (null) values with 0.
  • Hint: Use the fillna() method in Pandas.
# Starter Code
import pandas as pd

df = pd.read_csv("your_file.csv")
df.fillna(0, inplace=True)

Download here the your_file.csv file

Exercise 4: Create a Basic Plot

  • Objective: To practice creating a basic plot using Matplotlib.
  • Task: Plot a histogram of ages from the DataFrame you used in Exercise 3.
  • Hint: Use Matplotlib's hist() function.
# Starter Code
import matplotlib.pyplot as plt

plt.hist(df['age'], bins=20)
plt.show()

Exercise 5: Evaluate a Simple Model

  • Objective: To get a feel for basic model evaluation.
  • Task: Use the Scikit-learn library to fit a Linear Regression model on any two variables from the DataFrame you used in Exercise 3. Evaluate the model's performance using the Mean Squared Error (MSE) metric.
  • Hint: Use LinearRegression from Scikit-learn's linear_model module and mean_squared_error from the metrics module.
# Starter Code
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error

# Your code here

By working through these exercises, you'll solidify your understanding of the data analysis process and get hands-on experience with Python's data analysis libraries. Good luck, and remember: the key to mastering data analysis is practice, practice, practice!

1.4 Practical Exercises for Chapter 1: Introduction to Data Analysis and Python

Exercise 1: Define a Data Analysis Problem

  • Objective: To exercise your ability to frame a problem suitable for data analysis.
  • Task: Write down a problem statement or question that you would like to solve using data analysis. Be as specific as possible.
  • Hint: Examples of problem statements could be "What is the average age of customers who purchased a particular product?" or "How do temperature changes affect electricity consumption?"

Exercise 2: Data Collection with Python

  • Objective: Familiarize yourself with Python's capabilities for data collection.
  • Task: Use Python's requests library to fetch data from an open API of your choice.
  • Hint: Make sure to check the API's documentation for usage guidelines.
# Starter Code
import requests

response = requests.get("<https://api.example.com/your_endpoint>")
print(response.json())

Exercise 3: Basic Data Cleaning with Pandas

  • Objective: To clean a simple dataset using Python's Pandas library.
  • Task: Import a CSV file into a Pandas DataFrame and replace all NaN (null) values with 0.
  • Hint: Use the fillna() method in Pandas.
# Starter Code
import pandas as pd

df = pd.read_csv("your_file.csv")
df.fillna(0, inplace=True)

Download here the your_file.csv file

Exercise 4: Create a Basic Plot

  • Objective: To practice creating a basic plot using Matplotlib.
  • Task: Plot a histogram of ages from the DataFrame you used in Exercise 3.
  • Hint: Use Matplotlib's hist() function.
# Starter Code
import matplotlib.pyplot as plt

plt.hist(df['age'], bins=20)
plt.show()

Exercise 5: Evaluate a Simple Model

  • Objective: To get a feel for basic model evaluation.
  • Task: Use the Scikit-learn library to fit a Linear Regression model on any two variables from the DataFrame you used in Exercise 3. Evaluate the model's performance using the Mean Squared Error (MSE) metric.
  • Hint: Use LinearRegression from Scikit-learn's linear_model module and mean_squared_error from the metrics module.
# Starter Code
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error

# Your code here

By working through these exercises, you'll solidify your understanding of the data analysis process and get hands-on experience with Python's data analysis libraries. Good luck, and remember: the key to mastering data analysis is practice, practice, practice!