我有以下代码:
import pandas as pd
from pandas import datetime
from pandas import DataFrame as df
from pandas_datareader import data as web
import datetime
import numpy as np
stock = '^GSPC'
start = datetime.date(2000,1,1)
end = datetime.date.today()
data = web.DataReader(stock, 'yahoo',start, end)
data.index = pd.to_datetime(data.index, format ='%Y-%m-%d')
data['pct_day']= data['Adj Close'].pct_change()
df1 = df(data['pct_day'].gt(0.01))
运行最后一行后,出现以下错误:TypeError: 'DataFrame' object is not callable
。由于某种原因,如果我重新启动笔记本计算机,此命令将仅运行1次,然后出现此错误。您能告诉我为什么会出现此错误吗?
答案 0 :(得分:0)
用[]
代替()
,将boolean indexing
的最后一行更改为df
,并将data
更改为DataFrame
,以过滤相同的df1 = data[data['pct_day'].gt(0.01)]
,如掩码:< / p>
'Start Excel
On Error Resume Next
Set oExcel = GetObject(, "Excel.Application") 'Bind to existing instance of Excel
If Err.Number <> 0 Then 'Could not get instance of Excel, so create a new one
Err.Clear
On Error GoTo Error_Handler
Set oExcel = CreateObject("Excel.Application")
bExcelOpened = False
Else 'Excel was already running
bExcelOpened = True
End If
On Error GoTo Error_Handler