Dec-11-2020, 02:36 PM
I am currently trying to work through a YouTube tutorial and am stuck on the following error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
The error is being caused by this line in the following code:
if currentMax == max(Range, default = 0):
Any help would be greatly appreciated – thanks!
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
The error is being caused by this line in the following code:
if currentMax == max(Range, default = 0):
Any help would be greatly appreciated – thanks!
import yfinance as yf import datetime as dt import pandas as pd from pandas_datareader import data as pdr import matplotlib.pyplot as plt yf.pdr_override() start = dt.datetime(2019, 6, 1) now = dt.datetime.now() while stock != "quit": df = pdr.get_data_yahoo(stock, start, now) df['High'].plot(label = 'high') pivots = [] dates = [] counter = 0 lastPivot = 0 Range = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] dateRange = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] for i in df.index: currentMax = max(Range, default = 0) value = round(df["High"], 2) Range = Range[1:9] Range.append(value) dateRange = dateRange[1:9] dateRange.append(i) if currentMax == max(Range, default = 0): counter += 1 else: counter = 0 if counter == 5: lastPivot = currentMax dateloc = Range.index(lastPivot) lastDate = dateRange[dateloc] pivots.append(currentMax) dates.append(lastDate) print() timeD = dt.timedelta(days = 30) for index in range(len(pivots)): print(str(pivots[index]) + ": "+ str(dates[index])) plt.plot_date([dates[index] - (timeD * .075), dates[index] + timeD], [pivots[index], pivots[index]], linestyle = "-", linewidth = 2, marker = ",") plt.show() print() stock = input("Enter the stock symbol: ")