Updated post for csv file structure. csv file has the following structure:
Symbol
AAL
AAON
AAPL
ABCB
Tickers does not have quotation marks.
I have a problem with my code in Python. I am trying to download historical ESG data from Yahoo Finance using yfinance and NASDAQ tickers from .csv file. To download ESG data I am using a code below:
import pandas as pd
import yfinance as yf
import time
from random import randint
import yesg
import requests
# Read in your symbols
nasdaq = pd.read_csv('/path/to/file.csv')
# Endpoint(As far as I am concerned endpoint allows to download historical data from Yahoo)
url = "https://query2.finance.yahoo.com/v1/finance/esgChart"
# List of dataframes
dataframes = []
for symbol in nasdaq["ticker_code"]:
response = requests.get(url, params={"symbol": symbol})
if response.ok:
df = pd.DataFrame(response.json()["esgChart"]["result"][0]["symbolSeries"]
df["symbol"] = symbol
dataframes.append(df)
df = pd.concat(dataframes)
df["timestamp"] = pd.to_datetime(df["timestamp"], unit="s")
But there is an invalid synthax error in df["symbol"] = symbol. I can't find out, what could be the reason for the error. By the way, everything is okay with a file path in a row, I just wrote here a sample of a path.