Error in Python Code - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Error in Python Code (/thread-27365.html) |
Error in Python Code - ErnestTBass - Jun-04-2020 The following python code gives an error. %reload_ext nb_black import yfinance import pandas as pd import numpy import matplotlib.pyplot as plt portfolio_composition = [("MSFT", 0.5), ("AAPL", 0.2), ("GOOG", 0.2)] returns = pd.Dataframe({}) for t in portfolio_composition: name = t[0] ticker = yfinance.Ticker(name) data = ticker.history(interval="id") start = "2010-01-01", end = "2019-12-31" data["return_%s"(name)] = data["Close"].pct_change(1) returns.join(data[["returns_%s" % (name)]], how="outer").dropna()It is the start line and the error is now shown: I am not sure what is incorrect. At first it gave me an error on the line:returns = pd.Dataframe({})It did not like the dataframe. An attribute was missing. But now it is throwing this error. What bis wrogn with the syntax? Any help appreciated. Thanks in advance. Respectfully, ErnesrtTBass RE: Error in Python Code - buran - Jun-04-2020 start, end = "2010-01-01", "2019-12-31" RE: Error in Python Code - GOTO10 - Jun-04-2020 The syntax you've used in line 15 for assigning multiple variables is not valid in Python. You'd get the same error with something like a = 2, b = 3 . You can address this by assigning start and end on two separate lines, or this would also work:start, end = "2010-01-01", "2019-12-31" RE: Error in Python Code - ErnestTBass - Jun-04-2020 I will give it a try. Thank you for your help. The way that I showed in the codebox, was that the old way? I got this from legacy code. Respectfully, ErnestTBass RE: Error in Python Code - buran - Jun-04-2020 (Jun-04-2020, 03:54 PM)ErnestTBass Wrote: The way that I showed in the codebox, was that the old way?No, it was never a valid code. Probably you have typo - if it was semicolon instead of comma, it will be valid though unpythonic code |