nickmccullum / algorithmic-trading-python

The repository for freeCodeCamp's YouTube course, Algorithmic Trading in Python
2.41k stars 2.42k forks source link

append method is deprecated #43

Open solareklips opened 1 year ago

solareklips commented 1 year ago

I get this error

FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. final_dataframe = final_dataframe.append(

Have tried several things now with the pd.concat without luck. It's in "Looping Through The Tickers in Our List of Stocks"

final_dataframe = pd.DataFrame(columns = my_columns) for stock in stocks["Ticker"][:4]: api_url = f"https://sandbox.iexapis.com/stable/stock/{stock}/quote/?token={IEX_CLOUD_API_TOKEN}" data = requests.get(api_url).json() final_dataframe = final_dataframe.append( pd.Series([symbol, data['latestPrice'], data['marketCap'], 'N/A'], index = my_columns), ignore_index = True)

reyrocket commented 1 year ago

It is not an error. It is a warning. Your code will still work. if you don't want to get the warning. put this at the top of your code import warnings warnings.filterwarnings(action='ignore', category=FutureWarning)

npomfret commented 1 year ago

It is just a warning. But you can achieve the same outcome without a warning by using pd.concat(... and passing in a 1-row data frame, eg:

new_row = pd.DataFrame([[symbol, price, market_cap, 'N/A']], columns=my_columns)
df = pd.concat([df, new_row], ignore_index=True)
Nozipho1 commented 1 year ago

with this method how do you name the index or make it equal to my_columns?