Can not find Pyhton Quandl&Pandas Syntax Error

Tags: , , ,



I was following a tutorial from this guy and I was writing the exact same code to VS code except that Quandl is not written in uppercase anymore. I will leave a ss of the code here for who don’t want to watch video. reference code

https://www.youtube.com/watch?v=lN5jesocJjk&list=PLQVvvaa0QuDfKTOs3Keq_kaG2P55YRn5v&index=3

Here is the code I wrote -exact copy of the code above but it does not work idk why:

import pandas as pd 
import quandl
import math
#quandl.ApiConfig.api_key  = "it is not necessary in the video but I have API key here because I signed in to Quandl site"
df = quandl.get('WIKI/GOOGL')
df = df[['Adj. Open','Adj. High','Adj. Low','Adj. Close', 'Adj. Volume']]
df["HL_PCT"] = (df["Adj. High"] - df["Adj. Close"]) / df["Adj. Close"] * 100.0
df["PCT_change"] = (df["Adj. Close"] - df["Adj. Open"]) / df["Adj. Open"] * 100.0
df = df[['Adj. Close','HL_PCT','PCT_change','Adj. Volume']]
forecast_col = 'Adj. Close'
df.fillna(-99999, inplace=True)
forecast_out = int(math.ceil(0.01*len(df)))
df['label'] = df[forecast_col].shift(-forecast_out)
df.dropna(inplace=True)
print(df.tail())

Here is the terminal when I tried to run : terminal

ps : Code was working without any problem until I added forecast_out line, so API line does not effect the code.

Answer

According to the screenshot of the terminal you provided, the VS Code terminal is in the python interactive window. When we run the code, it executes the corresponding command in the terminal, but the python interactive window only recognizes the python code, so it displays “SyntaxError: invalid syntax“:

enter image description here

Solution: Exit this python interactive window. Please type “exit()” or close this terminal (Kill Terminal) and reopen a new terminal.

exit:

enter image description here

Run:

enter image description here



Source: stackoverflow