1 回答

TA貢獻1993條經驗 獲得超6個贊
刪除一列
del search_rank['isPartial']
添加計算列
search_rank['Rank'] = df.apply(lambda row: row[0]+row[1] + row[2], axis=1)
我用上面的修改測試了你的代碼,這里是完整的代碼
import yfinance as yf
from pytrends.request import TrendReq as tr
ticker = "TER"
pytrends = tr(hl='en-US', tz=360)
# =============================================================================
# Get Stock Information
# These variables are stored as DataFrames
# =============================================================================
stock = yf.Ticker(ticker)
i = stock.info
stock_info = {'Ticker':ticker}
stock_info.update(i)
# =============================================================================
# Get Google Trends Ranking for our Stock
# =============================================================================
longName = stock_info.get('longName')
shortName = stock_info.get('shortName').split(',')[0]
keywords = [ticker, longName, shortName]
pytrends.build_payload(keywords, timeframe='all')
search_rank = pytrends.interest_over_time()
del search_rank['isPartial']
search_rank['Rank'] = search_rank.apply(lambda row: row[0]+row[1]+row[2] , axis=1)
print(search_rank)
輸出:
Date TER Teradyne, Inc. Teradyne Rank
2004-01-01 25 0 1 26
2004-02-01 25 0 1 26
2004-03-01 29 0 1 30
添加回答
舉報