Unknown model· unknown
NVIDIA HelpSteer3 Preference
How to generate a CSV with python that contains stock price of AAPL each minute for the…
- User
How to generate a CSV with python that contains stock price of AAPL each minute for the last two years?
- Assistant
To generate a CSV with python that contains stock price of AAPL each minute for the last two years, you can use the Yahoo Finance API. Here's an example code that you can use:
pythonimport requests import json import pandas as pd # Set the start and end dates start_date = '2019-01-01' end_date = '2021-01-01' # Set the API URL url = 'https://query1.finance.yahoo.com/v7/finance/download/{}?period1={}&period2={}&interval=1m&events=history&includeAdjustedClose=true'.format('AAPL', start_date, end_date) # Make the API request response = requests.get(url) # Parse the response data = json.loads(response.text) # Create a dataframe from the data df = pd.DataFrame(data) # Save the dataframe to a CSV file df.to_csv('AAPL_stock_price.csv', index=False)This code uses the library to make an API request to Yahoo Finance. The API URL is constructed with the desired stock symbol ('AAPL'), start date, end date, and interval ('1m' for each minute). The response is then parsed as JSON and converted into a pandas DataFrame. Finally, the DataFrame is saved to a CSV file named 'AAPL_stock_price.csv'.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.