1

Below is my code to pull stock option data from a list of stock tickers. The code runs through all the tickers without error, but my dataframe (opt_df) meant to capture ALL the tickers' data ends up empty:

opt_df = DataFrame()

for symbol in tickers:
    try:
        ticker = yf.Ticker(symbol)
        opt = ticker.option_chain('2021-07-30')
        opt_df.append(opt)
    except ValueError:
        continue
JackW24
  • 135
  • 9
  • `DataFrame.append` is not an in-place operation. You will need to assign back to accumulate into the variable. `opt_df = opt_df.append(opt)` – Henry Ecker Jul 29 '21 at 00:03
  • That said. Sequential appends is an `O(N^2)` operation creating a single list of dataframes then performing a single `concat` is preferred. The general idea of how to implement this is covered here: [Creating and appending dataframes in a loop](https://stackoverflow.com/a/52815067/15497888) – Henry Ecker Jul 29 '21 at 00:06

0 Answers0