【问题标题】:Plotting Pandas Data绘制 Pandas 数据
【发布时间】:2015-10-29 23:44:05
【问题描述】:

我对@9​​87654321@ 行在以下代码中的作用有点困惑:

from datetime import datetime
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
data = pd.read_csv('ch08/spx.csv', index_col=0, parse_dates=True)
spx = data['SPX']
spx.plot(ax=ax, style='k-')
crisis_data = [
(datetime(2007, 10, 11), 'Peak of bull market'),
(datetime(2008, 3, 12), 'Bear Stearns Fails'),
(datetime(2008, 9, 15), 'Lehman Bankruptcy')
]
for date, label in crisis_data:
ax.annotate(label, xy=(date, spx.asof(date) + 50),
xytext=(date, spx.asof(date) + 200),
arrowprops=dict(facecolor='black'),
horizontalalignment='left', verticalalignment='top')
# Zoom in on 2007-2010
ax.set_xlim(['1/1/2007', '1/1/2011'])
ax.set_ylim([600, 1800])
ax.set_title('Important dates in 2008-2009 financial crisis')

【问题讨论】:

  • 哦,没关系,我想我想通了。我假设它指的是正在使用的列?
  • 是的,它提取名称为“SPX”的列

标签: python pandas


【解决方案1】:

它从 csv 文件中提取标题为 SPX 的列。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-11
    • 2015-09-29
    • 1970-01-01
    • 1970-01-01
    • 2015-08-03
    • 2018-10-29
    • 2019-04-20
    相关资源
    最近更新 更多