SyntaxError:尝试用Python打印时,Python 3.5的语法无效,即使是简单的打印(“Hello World”)

SyntaxError:尝试用Python打印时,Python 3.5的语法无效,即使是简单的打印(“Hello World”),python,syntax-error,Python,Syntax Error,我刚刚从我的桌面和其他杂项上删除了一堆文件。文件夹。我刚刚重新打开了我一直在做的项目,现在它不会打印,即使是一个简单的“Hello World”行144 我已经打开了一个新的python项目,我刚刚打印了(“hello world”),它工作得很好,所以我尝试将我的代码复制到同一个工作表中,并将其保存为不同的名称,但我得到了相同的错误 这是我在下面使用的代码;印刷品一直在底部 from pandas_datareader import data as dreader import pandas

我刚刚从我的桌面和其他杂项上删除了一堆文件。文件夹。我刚刚重新打开了我一直在做的项目,现在它不会打印,即使是一个简单的“Hello World”行144

我已经打开了一个新的python项目,我刚刚打印了(“hello world”),它工作得很好,所以我尝试将我的代码复制到同一个工作表中,并将其保存为不同的名称,但我得到了相同的错误

这是我在下面使用的代码;印刷品一直在底部

from pandas_datareader import data as dreader
import pandas as pd
from datetime import datetime
import dateutil.parser
from tkinter import *


# Sets the max rows that can be displayed
# when the program is executed
pd.options.display.max_rows = 200



# df is the name of the dataframe, it is 
# reading the csv file containing data loaded
# from yahoo finance(Date,Open,High,Low,Close
# volume,adj close,)the name of the ticker
# is placed before _data.csv i.e. the ticker aapl
# would have a csv file named aapl_data.csv.
df = pd.read_csv("cde_data.csv")


# resets the index back to the pandas default
# i.e. index starts at 0 for the first row and
# 1 for the second and continues by one till the
# end of the data in the above csv file. 
df.reset_index()



# the following code will allow for filtering of the datafram
# based on the year, day of week (dow), and month. It then gets
# applied to the dataframe and then can be used to sort data i.e
# print(df[(df.year == 2015) & (df.month == 5) & (df.dow == 4)])
# which will give you all the days in the month of May(df.month == 5), 
# that fall on a Thursday(df.dow == 4), in the year 2015 
# (df.year == 2015)
#
#      Month          Dow                      Year
# January    = 1  Monday    = 1  The year will be dispaly in a four
# February   = 2  Tuesday   = 2  digit format i.e. 2015
# March      = 3  Wednesday = 3
# April      = 4  Thursday  = 4
# May        = 5  Friday    = 5
# June       = 6
# July       = 7
# August     = 8
# September  = 9
# October    = 10
# November   = 11
# December   = 12
def year(x):
    return(x.year)
def dow(x):
    return(x.isoweekday())
def month(x):
    return(x.month)
df.Date            = df.Date.apply(dateutil.parser.parse)
df['year']         = df.Date.apply(year)
df['dow']          = df.Date.apply(dow)
df['month']        = df.Date.apply(month)


# The code below has a total of five sections all labeled by number.
# They are #1, #2, #3, #4, #5. Number one adds new columns to the df
# and populates them with data, number two filters out all the days
# that the market went down or flat for the day, number three filters
# out all of the days that the market went up or flat, number four 
# filters all of the days that  the market went up or down, and
# number five drops the excess columns and concats steps #2, #3, & #4. 


# 1
# there are five columns that are being added, up_down, up, down, 
# flat, and %chg. up, down, and flat are temporary and will be 
# deleted later on the other two up_down, and %chg will be permeant.
# The up_down column is derived from taking the 'close' column minus the
# 'open'column, this tells you how much the stock has moved for the day.
# The 'up' column is temporary and has a value of 'up' for all the rows
# of the DataFrame df. The 'down' column is temporary and has a value of  
# 'down' for all the rows of the DataFrame df. The 'down' column is   
# temporary and has a value of 'flat' for all the rows of the DataFrame 
# df. The '%chg' column is calculated by taking the results of the 
# 'up_down' divided by the 'close' column, and then times 100, which
# turns it into a percentage show what percent the stock moved up or 
# down for the day. All of the columns added below are added to the 
# DataFrame called df, which contains a a csv file(see code lines 14-20
# for information on the csv file contained in the DataFrame df). 
df['up_down']      = df['Close'] - df['Open'] 
df['up']           = 'up'   
df['down']         = 'down'
df['flat']         = 'flat'
df['%chg']         = ((df['up_down']/df['Close'])*100)      


# 2
# df column[up_down] is first filtered on the greater than zero
# criteria from the year 1984 on up and then is turned into df2.
# If the up_down column is greater than zero than this means that 
# the stock went up. Next df3 is set = to df2['up'], df3 now holds 
# just the days where the asset went up  
df2= (df[(df.year > 1984) & (df.up_down > 0)])
df3 = df2['up']



# 3
# df column[up_down] is first filtered on the less than zero
# criteria from the year 1984 on up and then is turned into df4.
# If the up_down column is less than zero than this means that 
# the stock went Down. Next df5 is set = to df4['down'], df5 now holds 
# just the days where the asset went down 
df4= (df[(df.year > 1984) & (df.up_down < 0)])
df5 = df4['down']



# 4
# df column[up_down] is first filtered on the equal to zero
# criteria from the year 1984 on up and then is turned into df6.
# If the up_down column is equal to zero than this means that 
# the stock did not move. Next df7 is set = to df6['flat'],df5 
# now holds just the days where the asset did not move at all 
df6= (df[(df.year > 1984) & (df.up_down == 0)])
df7 = df6['flat']



# 5
# The code below starts by droping the columns 'up', 'down', and 'flat'.
# These were temporary and were used to help filter data in the above
# code in sections two, three, and four. Finally we concat the 
# DataFrames df, df3, df5, and df7. We now have new 'up', 'down' and
# 'flat' columns that only display up, down, or flat when the criteria 
# is true.
df = df.drop(['up'], axis = 1)
df = df.drop(['down'], axis = 1)
df = df.drop(['flat'], axis = 1)
df = pd.concat([df,df3,df5,df7],axis =1, join_axes=[df.index])


df['openchgprevday']  =   ((df['Open']-1)-(df['Open'])

print("Hello World")

这里有一个额外的括号

df['openchgprevday']  =   ((df['Open']-1)-(df['Open'])

print("Hello World")
要纠正这一点,请执行以下操作:

df['openchgprevday']  =   (df['Open']-1)-(df['Open'])

print("Hello World")

这里有一个额外的括号

df['openchgprevday']  =   ((df['Open']-1)-(df['Open'])

print("Hello World")
要纠正这一点,请执行以下操作:

df['openchgprevday']  =   (df['Open']-1)-(df['Open'])

print("Hello World")

您可能正在使用Python2,请尝试打印“Hello world”(不带括号)我正在使用Python3.5,但无论如何我都尝试了,它不会起作用,这在Python2或Python3中不是无效语法;还有别的事。上一行缺少一个右括号。特别是在语法无效的情况下,将代码缩减到再现错误所需的最小值通常会有所帮助。在这种情况下,您会注意到上面的这一行是必需的,所以这一定是问题所在。感谢提示您可能正在使用python 2,请尝试
打印“Hello world”
(不带括号)我正在使用python 3.5,但无论如何我都尝试了它,它不会起作用。在python 2或3中,这不是无效语法;还有别的事。上一行缺少一个右括号。特别是在语法无效的情况下,将代码缩减到再现错误所需的最小值通常会有所帮助。在这种情况下,您会注意到上面的行是必需的,所以这一定是问题所在。谢谢您的提示,您的速度更快了。抢手货没关系,我从来没想到会这样。这是一个括号,谢谢,我想它仍然可以与一个简单的hello world一起工作,即使代码不好,但我想我学到了一些新的东西,你更快了。抢手货没关系,我从来没想到会这样。这是一个括号,谢谢,我想它仍然可以与一个简单的hello world一起工作,即使代码不好,但我想我学到了一些新的东西