×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Stocks Processing using Python Assignment Solution

June 12, 2024
Dr. Melissa
Dr. Melissa
🇺🇸 United States
Python
Dr. Melissa, with over 5 years of experience, earned her doctorate from the prestigious University of California, Berkeley. She has successfully completed 300+ Python assignments, demonstrating her deep understanding of programming concepts and her ability to deliver top-notch solutions. Driven by a passion for teaching and problem-solving, Dr. Melissa is dedicated to helping students excel in their Python endeavors.
Key Topics
  • Process Stocks in Files
Tip of the day
Start by understanding the problem, then choose relevant algorithms, and test incrementally. This approach helps in debugging and enhances clarity, especially in assignments involving machine learning models or neural networks.
News
In 2024, Python updates introduced improvements in TensorFlow and FastAPI, enhancing AI and web development for programming students. New cybersecurity standards were also implemented to protect open-source applications​

Process Stocks in Files

To complete the python assignment , for each question output your answers in the format:

  1. xxx
  2. yyy
  3. ...

where xxx and yyy (and so on) are the answers to each question.

# Q1 Stocks of how many companies are given in this data?

# Q2 How many of these companies start with the letter “A”?

# Q3 How many entries in the table correspond to companies starting with the letter “A”?

# Q4 What is the mean opening value for stocks of companies starting with the letter “A”? Round to two decimal digits

# Q5 What is the minimum opening value for stock with the name “AAL”? On which date did this value occur (return the date as given in the table)?

# Q6 What is the total volume of stocks traded of company “YUM”?

# Q7 What is the minimum volume of stocks of “FB” traded and on which day did this occur?

# Q8 Which company’s stock had the highest traded volume on a single day?

Solution:

import pandas as pd

stocks = pd.read_csv('all_stocks_5yr.csv')

  1. print('1.', len(pd.unique(stocks.Name))) # Preprocessing A_stocks = stocks[stocks.Name.str.startswith('A')]

  2. print('2.', len(pd.unique(A_stocks.Name)))

  3. print('3.', len(A_stocks))

  4. print('4.', round(A_stocks['open'].mean(),2))

  5. aal_stocks = stocks[stocks.Name == 'AAL'] print('5.', aal_stocks[aal_stocks.open == aal_stocks.open.min()].date.values[0])

  6. yum_stocks = stocks[stocks.Name == 'YUM'] print('6.', yum_stocks.volume.sum())

  7. fb_stocks = stocks[stocks.Name == 'FB'] print('7.', fb_stocks[fb_stocks.volume == fb_stocks.volume.min()].date.values[0])

  8. print('8.', stocks[stocks.volume == stocks.volume.max()].Name.values[0])

Similar Samples

Explore our diverse range of programming samples to see the quality and expertise we bring to every project. Each sample showcases our ability to tackle complex problems and deliver clear, efficient solutions. Whether you're a beginner or advanced programmer, our samples provide valuable insights and inspiration for your own work.