YFinance Error Help /u/Old-Course8991 Python Education

Here’s my code to get NASDAQ stock prices for a specific date-

—————

import yfinance as yf

import pandas as pd

def load_tickers_from_file(file_path):

“””

Load a list of tickers from a CSV file.

Assumes the file has a column named ‘Ticker’.

“””

try:

# Load the CSV file

df = pd.read_csv(file_path)

# Check if the ‘Ticker’ column exists

if ‘Ticker’ not in df.columns:

print(“Error: The CSV file does not contain a ‘Ticker’ column.”)

return []

# Return the list of tickers

return df[‘Ticker’].tolist()

except Exception as e:

print(f”Error reading the file: {e}”)

return []

def get_stock_data(ticker, date):

“””

Fetch stock data for a specific ticker on a specific date.

“””

stock_data = yf.download(ticker, start=date, end=date)

# Check if data exists for the given date

if stock_data.empty:

print(f”No data available for {ticker} on {date}.”)

else:

# Return the stock data for the given date

return stock_data

# Example usage: Retrieve stock data for all NASDAQ tickers from a CSV file on a specific date

file_path = r”C:UsersUserDesktopTradingnasdaq.csv” # Replace with the path to your CSV file

date = “2024-12-01” # Replace with your desired date (in format YYYY-MM-DD)

# Load tickers from the CSV file

nasdaq_tickers = load_tickers_from_file(file_path)

if nasdaq_tickers:

# Loop through each ticker and fetch its stock data for the given date

for ticker in nasdaq_tickers:

print(f”Fetching data for {ticker} on {date}…”)

stock_data = get_stock_data(ticker, date)

if stock_data is not None:

print(stock_data)

print(“n”) # Add a newline between results

else:

print(“No tickers found in the CSV file.”)

——————-

This is the error –

——————-

Fetching data for A on 2024-12-01…

[*********************100%***********************] 1 of 1 completed

1 Failed download:

[‘A’]: YFPricesMissingError(‘$%ticker%: possibly delisted; no price data found (1d 2024-12-01 -> 2024-12-01)’)

No data available for A on 2024-12-01.

Fetching data for AA on 2024-12-01…

[*********************100%***********************] 1 of 1 completed

1 Failed download:

[‘AA’]: YFPricesMissingError(‘$%ticker%: possibly delisted; no price data found (1d 2024-12-01 -> 2024-12-01)’)

No data available for AA on 2024-12-01.

Fetching data for AACG on 2024-12-01…

[*********************100%***********************] 1 of 1 completed

1 Failed download:

[‘AACG’]: YFPricesMissingError(‘$%ticker%: possibly delisted; no price data found (1d 2024-12-01 -> 2024-12-01)’)

No data available for AACG on 2024-12-01.

Fetching data for AACT on 2024-12-01…

[*********************100%***********************] 1 of 1 completed

…. and so on.

———————————-

What am I doing wrong? Any help would be appreciated.

Thanks

submitted by /u/Old-Course8991
[link] [comments]

​r/learnpython Here’s my code to get NASDAQ stock prices for a specific date- ————— import yfinance as yf import pandas as pd def load_tickers_from_file(file_path): “”” Load a list of tickers from a CSV file. Assumes the file has a column named ‘Ticker’. “”” try: # Load the CSV file df = pd.read_csv(file_path) # Check if the ‘Ticker’ column exists if ‘Ticker’ not in df.columns: print(“Error: The CSV file does not contain a ‘Ticker’ column.”) return [] # Return the list of tickers return df[‘Ticker’].tolist() except Exception as e: print(f”Error reading the file: {e}”) return [] def get_stock_data(ticker, date): “”” Fetch stock data for a specific ticker on a specific date. “”” stock_data = yf.download(ticker, start=date, end=date) # Check if data exists for the given date if stock_data.empty: print(f”No data available for {ticker} on {date}.”) else: # Return the stock data for the given date return stock_data # Example usage: Retrieve stock data for all NASDAQ tickers from a CSV file on a specific date file_path = r”C:UsersUserDesktopTradingnasdaq.csv” # Replace with the path to your CSV file date = “2024-12-01″ # Replace with your desired date (in format YYYY-MM-DD) # Load tickers from the CSV file nasdaq_tickers = load_tickers_from_file(file_path) if nasdaq_tickers: # Loop through each ticker and fetch its stock data for the given date for ticker in nasdaq_tickers: print(f”Fetching data for {ticker} on {date}…”) stock_data = get_stock_data(ticker, date) if stock_data is not None: print(stock_data) print(“n”) # Add a newline between results else: print(“No tickers found in the CSV file.”) ——————- This is the error – ——————- Fetching data for A on 2024-12-01… [*********************100%***********************] 1 of 1 completed 1 Failed download: [‘A’]: YFPricesMissingError(‘$%ticker%: possibly delisted; no price data found (1d 2024-12-01 -> 2024-12-01)’) No data available for A on 2024-12-01. Fetching data for AA on 2024-12-01… [*********************100%***********************] 1 of 1 completed 1 Failed download: [‘AA’]: YFPricesMissingError(‘$%ticker%: possibly delisted; no price data found (1d 2024-12-01 -> 2024-12-01)’) No data available for AA on 2024-12-01. Fetching data for AACG on 2024-12-01… [*********************100%***********************] 1 of 1 completed 1 Failed download: [‘AACG’]: YFPricesMissingError(‘$%ticker%: possibly delisted; no price data found (1d 2024-12-01 -> 2024-12-01)’) No data available for AACG on 2024-12-01. Fetching data for AACT on 2024-12-01… [*********************100%***********************] 1 of 1 completed …. and so on. ———————————- What am I doing wrong? Any help would be appreciated. Thanks submitted by /u/Old-Course8991 [link] [comments] 

Here’s my code to get NASDAQ stock prices for a specific date-

—————

import yfinance as yf

import pandas as pd

def load_tickers_from_file(file_path):

“””

Load a list of tickers from a CSV file.

Assumes the file has a column named ‘Ticker’.

“””

try:

# Load the CSV file

df = pd.read_csv(file_path)

# Check if the ‘Ticker’ column exists

if ‘Ticker’ not in df.columns:

print(“Error: The CSV file does not contain a ‘Ticker’ column.”)

return []

# Return the list of tickers

return df[‘Ticker’].tolist()

except Exception as e:

print(f”Error reading the file: {e}”)

return []

def get_stock_data(ticker, date):

“””

Fetch stock data for a specific ticker on a specific date.

“””

stock_data = yf.download(ticker, start=date, end=date)

# Check if data exists for the given date

if stock_data.empty:

print(f”No data available for {ticker} on {date}.”)

else:

# Return the stock data for the given date

return stock_data

# Example usage: Retrieve stock data for all NASDAQ tickers from a CSV file on a specific date

file_path = r”C:UsersUserDesktopTradingnasdaq.csv” # Replace with the path to your CSV file

date = “2024-12-01” # Replace with your desired date (in format YYYY-MM-DD)

# Load tickers from the CSV file

nasdaq_tickers = load_tickers_from_file(file_path)

if nasdaq_tickers:

# Loop through each ticker and fetch its stock data for the given date

for ticker in nasdaq_tickers:

print(f”Fetching data for {ticker} on {date}…”)

stock_data = get_stock_data(ticker, date)

if stock_data is not None:

print(stock_data)

print(“n”) # Add a newline between results

else:

print(“No tickers found in the CSV file.”)

——————-

This is the error –

——————-

Fetching data for A on 2024-12-01…

[*********************100%***********************] 1 of 1 completed

1 Failed download:

[‘A’]: YFPricesMissingError(‘$%ticker%: possibly delisted; no price data found (1d 2024-12-01 -> 2024-12-01)’)

No data available for A on 2024-12-01.

Fetching data for AA on 2024-12-01…

[*********************100%***********************] 1 of 1 completed

1 Failed download:

[‘AA’]: YFPricesMissingError(‘$%ticker%: possibly delisted; no price data found (1d 2024-12-01 -> 2024-12-01)’)

No data available for AA on 2024-12-01.

Fetching data for AACG on 2024-12-01…

[*********************100%***********************] 1 of 1 completed

1 Failed download:

[‘AACG’]: YFPricesMissingError(‘$%ticker%: possibly delisted; no price data found (1d 2024-12-01 -> 2024-12-01)’)

No data available for AACG on 2024-12-01.

Fetching data for AACT on 2024-12-01…

[*********************100%***********************] 1 of 1 completed

…. and so on.

———————————-

What am I doing wrong? Any help would be appreciated.

Thanks

submitted by /u/Old-Course8991
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *