#StackBounty: #python #python-3.x #pandas #multi-index #ta-lib Value error on multiindex pandas dataframe

Bounty: 150

I am using the package from here. What i am trying to do is calculate the Stoch value for each ticker.
I have the following code:

import lxml
from urllib.request import urlopen
from bs4 import BeautifulSoup
import pandas as pd
from pandas import datetime
from pandas import DataFrame as df
# import matplotlib
from pandas_datareader import data as web
import matplotlib.pyplot as plt
import datetime
import numpy as np
import ta


html = urlopen('https://en.wikipedia.org/wiki/NIFTY_50')
soup = BeautifulSoup(html,'lxml')
niftylist_raw = soup.find('table', {'class': 'wikitable sortable'})

nifty_symbol =[]

for row in niftylist_raw.findAll('tr')[1:]:
    nifty_symbols = row.findAll('td')[1].text
    nifty_symbol.append(nifty_symbols)
tickerss = nifty_symbol

df = web.DataReader(tickerss, 'yahoo')


stoch1 = ta.momentum.StochasticOscillator(high= df['High'], low = df['Low'], close = df['Close'], n=14, fillna=False)

The code works till point.

I am having trouble with, if i do:

stoch1.stoch()

It produces the following error:

ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

What can i do to fix this error?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.