Knowee
Questions
Features
Study Tools

use python to do:Download daily data for Amazon (AMZN), Netflix (NFLX) and Bank of America (BA) from 2/1/2011 to the present day and retain Adj Close only. Name the dataframe xdata.

Question

use python to do:Download daily data for Amazon (AMZN), Netflix (NFLX) and Bank of America (BA) from 2/1/2011 to the present day and retain Adj Close only. Name the dataframe xdata.

🧐 Not the exact question you are looking for?Go ask a question

Solution

To download the daily data for Amazon (AMZN), Netflix (NFLX) and Bank of America (BA) from 2/1/2011 to the present day and retain Adj Close only, you can use the pandas_datareader library in Python. Here's how you can do it:

Step 1: Import necessary libraries

import pandas as pd
import pandas_datareader as web
from datetime import datetime

Step 2: Define the start and end dates

start = datetime(2011, 2, 1)
end = datetime.now()

Step 3: Download the data

amzn = web.DataReader('AMZN', 'yahoo', start, end)
nflx = web.DataReader('NFLX', 'yahoo', start, end)
ba = web.DataReader('BA', 'yahoo', start, end)

Step 4: Retain only the 'Adj Close' column

amzn = amzn[['Adj Close']]
nflx = nflx[['Adj Close']]
ba = ba[['Adj Close']]

Step 5: Rename the 'Adj Close' column to the respective stock symbol

amzn.rename(columns={'Adj Close': 'AMZN'}, inplace=True)
nflx.rename(columns={'Adj Close': 'NFLX'}, inplace=True)
ba.rename(columns={'Adj Close': 'BA'}, inplace=True)

Step 6: Merge the dataframes

xdata = pd.concat([amzn, nflx, ba], axis=1)

Now, xdata is the dataframe that contains the 'Adj Close' data for Amazon, Netflix, and Bank of America from 2/1/2011 to the present day.

Please note that you need to have the pandas_datareader library installed. If you haven't installed it yet, you can do so by running !pip install pandas_datareader in your Jupyter notebook or pip install pandas_datareader in your terminal.

This problem has been solved

Similar Questions

use python to: Write a code to download monthly data of the following tickers for the period from December 2011 to December 2022: ['AAPL','MSFT','GOOG','AMZN','TSLA','BRK-A','NVDA','UNH','JNJ','V','WMT','JPM','PG','XOM','MA','CVX','HD','BAC','PFE','LLY','KO','COST','DIS','AVGO','PEP','TMO','CSCO','CMCSA','ORCL','ABT']. Process monthly returns for the stocks (in a DataFrame), the market (a Series, using ^GSPC), and the risk-free rate (a Series, using ^IRX). Display the three variables.

Available for download from the final assessment folder are two csv files which contain daily unit prices for two Australia-based funds (labelled Fund A and Fund B) since inception. According to their fund profiles, they claim to be investing in high quality global companies including US big tech. a. For each of the data files, import the net asset value (NAV) as a Pandas dataframe. Fix any bugs in the data including ensuring there are no duplication in the dates. Once the data has been cleaned and sorted appropriately, compute the daily returns for each of the funds.(5 marks) b. Download the last 10 years of daily prices of NDQ.AX, an Exchange Traded Fund (ETF) on the Australian Stock Exchange that tracks the NASDAQ 100 index. Compute its daily returns.(5 marks)

A Data Analyst best toolkit includesPandasAnacondaPython and RBoth a & b

a) Download the Data from Blackboard. B) Launch JupyterNotebook. C) Create a new Notebook. D) Import pandas and numpy libraries. E) Import dataand name it df

Look at the image above. Which data will this query extract?SELECT yearFROM moviesSQLCopyData highlighted in 1Data highlighted in 2

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.