with open (csvfile) as data:
datareader = csv.reader(data , delimiter=',')
next(data)
for x in datareader:
tick = x[0]
d = pd.to_datetime(x[1] , "%m/%d/%Y")
t = pd.to_datetime(x[2] , "%H:%M")
m = x[6]
std = datetime(2015,9,6,17,40)
etd = datetime(2015,9,11,16,36)
print ("Start Time: ", std, "Value: ", m[std])
我收到此错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\MyPrograms\anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile
execfile(filename, namespace)
File "C:\MyPrograms\anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 85, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File "Z:/WORK/Programming/Python/Scripts/untitled1.py", line 64, in <module>
print ("startTradeDate: ", std, "Value: ", m[std])
TypeError: string indices must be integers
它应该打印出数据&#34; m&#34;在指定的日期和时间,但它给我上述错误。当唯一的方法是传递日期时间索引时,我不明白我应该如何传递一个整数。这就是我试图从csv索引日期和时间,但不管我做了什么都没有做到。
我想我只是没理解如何从CSV文件中标记和检索x / y坐标,然后能够通过python指向该位置。我的问题有意义吗?上面的代码只是我失败的尝试之一。