我正在尝试在带有 notion-py 的概念表行中使用 yfinance 显示股息
这是我正在使用的代码
from notion.client import NotionClient
from datetime import datetime
import pandas as pd
client = NotionClient(token_v2="mytoken")
cv = client.get_collection_view("tablepageurl")
data = pd.DataFrame()
stock_list = ['XSH.TO', 'ZFL.TO','EEMV', 'ACWV', 'XEF.TO', 'XIC.TO', 'VTI']
start = '2019-10-1'
end = '2020-10-30'
for i in stock_list:
series = yf.Ticker(i).dividends.loc[start:end]
data = pd.concat([data, series], axis=1)
row = cv.collection.add_row()
row.shmoney = stock_list
tickers = ('XSH.TO', 'ZFL.TO','EEMV', 'ACWV', 'XEF.TO', 'XIC.TO', 'VTI')
for ticker in tickers:
price = yf.Ticker(ticker)
row = cv.collection.add_row()
hist = price.history(period="1d")
row.SYMBL = ticker
row.DayReturn = float(round(((hist.Close[0]) - (hist.Open[0]) ) / (hist.Open[0])*100,2))
我收到此错误提示
File "/Users/ajj/Documents/NotionStockAPI/notionapi_env/lib/python3.9/site-packages/notion/collection.py", line 583, in _convert_python_to_notion
raise TypeError(
TypeError: Value passed to property 'shmoney' must be an int or float.
“shmoney”是 Notion 中表行的名称,我在玩这些名称,因为我认为名称与代码冲突(我真的迷路了)
当我拿出
from notion.client import NotionClient
from datetime import datetime
import pandas as pd
client = NotionClient(token_v2="mytoken")
cv = client.get_collection_view("tablepageurl")
data = pd.DataFrame()
stock_list = ['XSH.TO', 'ZFL.TO','EEMV', 'ACWV', 'XEF.TO', 'XIC.TO', 'VTI']
start = '2019-10-1'
end = '2020-10-30'
for i in stock_list:
series = yf.Ticker(i).dividends.loc[start:end]
data = pd.concat([data, series], axis=1)
row = cv.collection.add_row()
row.shmoney = stock_list
一切都很好。