【问题标题】:Export a list of stock prices to excel将股票价格列表导出到 Excel
【发布时间】:2018-04-18 18:47:10
【问题描述】:

我想使用 python 导入股票价格列表并导出到 excel。我可以附加价格列表,但无法导出。请帮忙。 下面是我刚接触 Python 的代码。

import pandas as pd

import pandas_datareader.data as web

import datetime

import matplotlib 

import matplotlib.pyplot as plt

start = datetime.datetime(2015, 1, 1)

end = datetime.date.today()

stocklist=["ANDHRABANK.NS","HDFCBANK.NS","IDBI.NS","PNB.NS"]

prices=[]

for i in stocklist:

  f=web.DataReader(i, 'yahoo', start, end)

prices.append(f)

print prices

我得到以下结果。

[                 Open        High        Low      Close  Adj Close      Volume
Date                                                                          
2015-01-01  95.000000  100.949997  94.000000  96.449997  89.612679  17072046.0
2015-01-02  97.250000   98.050003  95.650002  96.250000  89.426872   4886258.0
2015-01-05  96.099998   96.800003  93.900002  94.150002  87.475739   3937461.0
2015-01-06  93.599998   93.599998  88.650002  89.349998  83.015999   4531779.0
2015-01-07  89.349998   90.500000  86.699997  88.500000  82.226265   5134680.0
2015-01-08  89.650002   91.750000  89.500000  91.000000  84.549042   3333586.0

现在我想将收盘价导出并绘制到我的 Dropbox 中现有的 excel 文件中。

支持的坦克。

【问题讨论】:

  • 另外edit你的问题包括你当前的代码
  • 请说明您的问题

标签: python excel python-2.7 stocks


【解决方案1】:

试试 pandas.ExcelWriter

In [1]: import pandas as pd
pd
In [2]: pd.ExcelWriter?
...
Init signature: pd.ExcelWriter(cls, path, engine=None, **kwargs)
Docstring:     
Class for writing DataFrame objects into excel sheets, default is to use
xlwt for xls, openpyxl for xlsx.  See DataFrame.to_excel for typical usage.
In [6]: pd.DataFrame.to_excel?
-----
If passing an existing ExcelWriter object, then the sheet will be added
to the existing workbook.  This can be used to save different
DataFrames to one workbook:

>>> writer = pd.ExcelWriter('output.xlsx')
>>> df1.to_excel(writer,'Sheet1')
>>> df2.to_excel(writer,'Sheet2')
>>> writer.save()

您仍然需要弄清楚保管箱部分

【讨论】:

  • 感谢您的支持。你的回答很有帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-08-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多