【发布时间】:2016-01-11 07:59:50
【问题描述】:
我有一个 python 函数,可以将雅虎财务数据存储到数据框。
from pandas.io.data import DataReader
bars= DataReader(symbol, "yahoo",hist_date, today)
我得到的结果返回到 bar 如下
数据帧:
Open High Low Close Volume Adj Close\nDate
\n2011-01-12 2.00 2.00 2.00 2.00 100 1.891661
\n2011-01-13 2.00 2.00 1.92 2.00 6800 1.891661
\n2011-01-14 1.84 2.24 1.84 2.19 1500 2.071369
\n2011-01-18 2.25 2.25 2.02 2.02 4300 1.910578
\n2011-01-19 2.07 2.12 2.07 2.12 3400 2.005161
\n2011-01-20 2.21 2.21 2.10 2.17 5000 2.052452
\n2011-01-21 2.25 2.25 2.20 2.20 600 2.080827
\n2011-01-24 2.20 2.20 2.12 2.18 2300 2.061911
现在我想将日期列作为数据框的索引字段。此外,当我尝试在表格中显示数据框时,我无法在任何地方显示日期字段。是不是因为在列标题和列数据之前有一个 \n 。
【问题讨论】:
-
print bars.index是什么? -
display the dataframe in a table是什么意思? -
我试图使用数据表在 html 中显示数据框的内容
-
那你试试
bars.to_html('page.html')? -
或者你想先重置索引:
bars.reset_index().to_html('page1.html')
标签: python pandas dataframe yahoo-finance