【发布时间】:2021-03-13 19:27:18
【问题描述】:
我正在尝试编写一个简单的程序,它使用 csv 中的股票列表。我正在使用名为nsetools 的库,它为印度股市提供股票信息。
Loop 应该从 csv 中选择股票代码并打印股票的当前市场价格。
但是,我收到以下错误:
Traceback (most recent call last):
File "C:/Users/anoopmah/AppData/Roaming/JetBrains/PyCharmCE2020.3/scratches/scratch_7.py", line 15, in <module>
p = nse.get_quote('temp')['lastPrice']
TypeError: 'NoneType' object is not subscriptable
代码:
import nsetools
import pandas as pd
from nsetools import Nse
nse = Nse()
#Import CSV into dataframe
filepath = "C:/temp/Stock/stocklist.csv"
df = pd.read_csv(filepath,encoding='windows-1252')
for i in range(0,len(df)):
temp = df["Name"][i]
print(temp)
p = nse.get_quote('temp')['lastPrice']
print(p)
【问题讨论】:
-
如果答案有效,请务必点击答案旁边的绿色复选标记,并尝试直接提出问题让人们回答。