Pandas Capstone Project: Analyzing Apple and Tesla stocks
Pandas Capstone Project: Analyzing Apple and Tesla stocks Data Science Project
Intro to Pandas for Data Analysis

Pandas Capstone Project: Analyzing Apple and Tesla stocks

Explore real-world data with this engaging capstone project! Analyze daily stock prices of Apple and Tesla from Feb 2022 to Feb 2023 using Python's Pandas. You'll tackle 28 hands-on activities, from statistics to data manipulation, and even create basic plots. Gain valuable data analysis skills in a user-friendly format!
Start this project
Pandas Capstone Project: Analyzing Apple and Tesla stocksPandas Capstone Project: Analyzing Apple and Tesla stocks
Project Created by

Anurag Verma

Project Activities

All our Data Science projects include bite-sized activities to test your knowledge and practice in an environment with constant feedback.

All our activities include solutions with explanations on how they work and why we chose them.

codevalidated

Read CSV file

Read the stock data CSV files for Apple and Tesla, assign them to apple_df and tesla_df respectively, and ensure that the dates are parsed correctly.

multiplechoice

What is the shape for stocks data

Select the appropriate shape for the apple_df and tesla_df dataframes.

codevalidated

Read specific columns

Create a new dataframe called tesla_column_df by reading only the Date and Close columns from the Tesla stock data CSV file.

codevalidated

Read specific rows

Read Apple stock data for March 2022 and store it in apple_row_df dataframe.

input

What is the mean closing price of Apple

Using apple_df, what is the mean Close price rounded to the nearest integer? Example, if the value is 90.182, enter 90. If it's 90.871, enter 91.

multiplechoice

Select the correct mean

Select the correct mean for apple_df and tesla_df dataframes.

multiplechoice

Find the maximum and minimum values

Find the maximum and minimum values of the Close column for both Apple and Tesla stock data and select all correct answers.

multiplechoice

Find the average and median values

Select the correct average and median values of the Close column for both Apple and Tesla stocks in this activity.

codevalidated

Create a new column

Create a new column called High_Low_Diff in both the Apple and Tesla data to calculate the difference between the "High" and "Low" values.

codevalidated

Rename columns

Rename the columns in the Apple and Tesla data to make them more readable as follows:

For the Apple data dataset, the column:

{'Open': 'Apple_Open', 'High': 'Apple_High', 'Low': 'Apple_Low', 'Close': 'Apple_Close', 'Adj Close': 'Apple_Adj_Close', 'Volume': 'Apple_Volume'}

For the Tesla data dataset, the column:

{'Open': 'Tesla_Open', 'High': 'Tesla_High', 'Low': 'Tesla_Low', 'Close': 'Tesla_Close', 'Adj Close': 'Tesla_Adj_Close', 'Volume': 'Tesla_Volume'}
codevalidated

Drop all the rows of May 2022

Drop all the rows from apple_df and tesla_df that correspond to the month of May 2022.

codevalidated

Create new rows

Add new rows to the Apple and Tesla data for a new day in this activity.

Apple dataset new row details:

{'Date': pd.to_datetime('2023-02-18'), 'Apple_Open': 300.0, 'Apple_High': 305.0, 'Apple_Low': 295.0, 'Apple_Close': 303.0, 'Apple_Adj_Close': 303.0, 'Apple_Volume': 50000000, 'High_Low_Diff': 10.0}

Tesla dataset new row details:

{'Date': pd.to_datetime('2023-02-18'), 'Tesla_Open': 700.0, 'Tesla_High': 710.0, 'Tesla_Low': 690.0, 'Tesla_Close': 702.0, 'Tesla_Adj_Close': 702.0, 'Tesla_Volume': 20000000, 'High_Low_Diff': 20.0}
multiplechoice

Close value of february month

Select all the correct options.

input

Which month has minimum Close value

Write month name for both Apple and Tesla dataset sperated by comma like this: January, April.

input

Which month has maximum Close value

Write month name for both Apple and Tesla dataset sperated by comma like this: January, April.

input

Write the mean of the Close value

Write mean value for both Apple and Tesla dataset sperated by comma like this: 2683.919982, 4016.179992.

codevalidated

Filter the data based on specific criteria

In this activity, we will filter the Apple and Tesla data to select only the rows that meet a specific criteria. We will filter the data to select rows where the closing price is greater than the opening price for both stocks. The results for Apple and Tesla will be stored in apple_pos and tesla_pos dataframes, respectively.

input

What is the shape of above filtered `apple_pos` dataframe

Write in this format: (120, 12)

input

What is the shape of above filtered `tesla_pos` dataframe

Write in this format: (120, 12)

codevalidated

Filter Data Using Multiple Criteria

In this activity, we will filter the data for Apple and Tesla stocks based on multiple criteria. We will filter the data to select rows where the volume is greater than 50 million and the closing price is greater than the opening price for both stocks. The results for Apple and Tesla will be stored in apple_filtered and tesla_filtered dataframes, respectively.

codevalidated

Filter Data Based on Column Values

In this activity, we will filter the data for Apple and Tesla stocks based on the values in a specific column. We will filter the data for both stocks where the closing price is greater than or equal to 280. The results for Apple and Tesla will be stored in apple_filtered_close and tesla_filtered_close dataframes, respectively.

codevalidated

Read stock files and filter them for plotting

In this activity, we will re-read the apple.csv and tesla.csv stock files and filter them for plotting. We will ensure that the dates are parsed correctly. The filtered data will be stored in the apple_pos and tesla_pos dataframes. We will filter the data from August 2022 onwards to select rows where the closing price is greater than the opening price for both Apple and Tesla stocks.

codevalidated

Plot Apple Close prices starting in August 2022

Plot the Close price in apple_df using Date as its x axis and Close as its y axis. Plot only the prices starting in August 1st, 2022 (inclusive).

  • The title of the chart must be "Apple Close Price from August 2022"
  • The color of the line must be "black"

Make sure you're storing the results of .plot in the variable ax. It should look something like:

apple close price plotted since August 2022

multiplechoice

Choose correct options based on line plot.

In this activity, we will plot the line chart for the filtered dataframes apple_pos and tesla_pos using the plot function.

multiplechoice

Choose correct options based on line plot

In this activity, we will plot the line chart for the filtered dataframes apple_pos and tesla_pos using the plot function. Use the Date column for the x-axis and Volume column for the y-axis. Which of the following statements are correct?

multiplechoice

Choose correct options based on bar plot

In this activity, we will plot the bar chart for the filtered dataframes apple_pos and tesla_pos using the plot function. Use the Date column for the x-axis and Volume column for the y-axis. Which of the following statements are correct?

multiplechoice

Choose correct options based on bar plot

In this activity, we will plot the bar chart for the filtered dataframes apple_pos and tesla_pos using the plot function. Use the Date column for the x-axis and Close column for the y-axis. Which of the following statements are correct?

multiplechoice

Choose correct options based on pie plot

In this activity, we will plot the pie chart for the filtered dataframes apple_pos and tesla_pos using the plot function. Use the Date column for the x-axis and Close column for the y-axis. Which of the following statements are correct?

multiplechoice

Choose correct option based on pie plot

In this activity, we will plot the pie chart for the filtered dataframes apple_pos and tesla_pos using the plot function. Use the Date column for the x-axis and Volume column for the y-axis. Which of the following statements are correct?

multiplechoice

Choose correct based on scatter plot

In this activity, we will plot the scatter plot for the filtered dataframes apple_pos and tesla_pos using the plot function. Use the Date column for the x-axis and Close column for the y-axis. Which of the following statements are correct?

Pandas Capstone Project: Analyzing Apple and Tesla stocksPandas Capstone Project: Analyzing Apple and Tesla stocks
Project Created by

Anurag Verma

What's up, friends! 👋 I'm a computer science student about to finish my last year of college. 🎓 I LOVE writing code! ❤️ It makes me so happy! 😄 Whether I'm goofing in notebooks 📓 or coding in Python 🐍, writing programs is a blast! 💥

What's up, friends! 👋 I'm a computer science student about to finish my last year of college. 🎓 I LOVE writing code! ❤️ It makes me so happy! 😄 Whether I'm goofing in notebooks 📓 or coding in Python 🐍, writing programs is a blast! 💥

This project is part of

Intro to Pandas for Data Analysis

Explore other projects