Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in Python Code
#1
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:

Error:
File "<ipython-input-1-c1daa2af4c39>", line 15 start = "2010-01-01", end = "2019-12-31" ^ SyntaxError: can't assign to literal
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
Reply


Messages In This Thread
Error in Python Code - by ErnestTBass - Jun-04-2020, 12:00 PM
RE: Error in Python Code - by buran - Jun-04-2020, 12:07 PM
RE: Error in Python Code - by GOTO10 - Jun-04-2020, 12:08 PM
RE: Error in Python Code - by ErnestTBass - Jun-04-2020, 03:54 PM
RE: Error in Python Code - by buran - Jun-04-2020, 05:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Code error from Fundamentals of Python Programming van Richard L. Halterman Heidi 12 1,814 Jul-25-2023, 10:32 PM
Last Post: Skaperen
  Syntax error while executing the Python code in Linux DivAsh 8 1,761 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Compiles Python code with no error but giving out no output - what's wrong with it? pythonflea 6 1,637 Mar-27-2023, 07:38 AM
Last Post: buran
  Error in if-then-else python code Led_Zeppelin 6 2,460 Jul-27-2022, 07:53 PM
Last Post: deanhystad
  Facing error while executing below Python code ramu4651 1 5,803 Jan-26-2021, 06:40 PM
Last Post: ibreeden
  Skeleton file export error Python Code pepapoha 4 3,569 Nov-17-2020, 02:06 AM
Last Post: pepapoha
  Compiling Python 3.8.5 source code results in build error Deepan 0 2,211 Sep-14-2020, 04:11 AM
Last Post: Deepan
  Syntax error in python code sample ErnestTBass 5 3,174 Aug-14-2020, 07:14 PM
Last Post: deanhystad
  Python Code error Riteshfrancis 2 2,465 May-21-2020, 06:37 AM
Last Post: Riteshfrancis
  Simple python code error cls0724 5 3,392 Mar-12-2020, 07:45 PM
Last Post: stullis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020