小编Jef*_*eff的帖子

如何从pandas数据帧中提取日期索引以在matplotlib中用作x轴

我试图在pandas数据帧中绘制数据,使用索引(日期和时间)作为x轴,数据帧中的其余数据作为实际数据.这是我现在正在尝试的内容:

from matplotlib.finance import candlestick2

bars[['open','high','low','close']].head()


tickdatetime         open        high        low         close          

2012-09-20 09:00:00  1447.50     1447.50     1447.00     1447.00

2012-09-20 09:01:00  1447.00     1447.25     1447.00     1447.25

2012-09-20 09:02:00  1447.25     1447.75     1447.25     1447.50

2012-09-20 09:03:00  1447.75     1447.75     1447.25     1447.50

2012-09-20 09:04:00  1447.25     1447.50     1447.25     1447.50

fig,ax = plt.subplots()
ax.plot_date(bars.ix.to_pydatetime(), s, 'v-')
fig,ax = plt.subplots()
ax.plot_date(bars.ix.to_pydatetime(), s, 'v-')
ax = fig.add_axes([0.1, 0.2, 0.85, 0.7])
ax.autoscale_view()
linecol, rectcol =  candlestick2(ax,bars['open'],bars['close'],bars['high'],bars['low'],width=.5,colorup='g',colordown''r',alpha=1) 
z  = rectcol.get_zorder()
linecol.set_zorder(0.9*z)
Run Code Online (Sandbox Code Playgroud)

但我得到这个错误:

AttributeError                            Traceback (most recent call last)
<ipython-input-57-d62385067ceb> in <module>()
1 fig,ax …
Run Code Online (Sandbox Code Playgroud)

matplotlib pandas

6
推荐指数
1
解决办法
1826
查看次数

使用日期时间作为 x 轴时,如何使散景忽略缺少的日期

我正在查看散景文档中的烛台示例,可在此处找到:

https://github.com/bokeh/bokeh/blob/master/examples/plotting/file/candlestick.py

我试图找出一种消除 x 轴中没有数据的“空格”的好方法。

具体来说,对于示例中使用的 MSFT 等财务数据,没有周末和节假日的数据。当没有日期数据时,有没有办法告诉散景不要在图表中留下空白?

为方便起见,这里粘贴了上面链接中的示例代码:

from math import pi
import pandas as pd

from bokeh.sampledata.stocks import MSFT
from bokeh.plotting import *

df = pd.DataFrame(MSFT)[:50]
df['date'] = pd.to_datetime(df['date'])

mids = (df.open + df.close)/2
spans = abs(df.close-df.open)

inc = df.close > df.open
dec = df.open > df.close
w = 12*60*60*1000 # half day in ms

output_file("candlestick.html", title="candlestick.py example")

figure(x_axis_type = "datetime", tools="pan,wheel_zoom,box_zoom,reset,previewsave",
   width=1000, name="candlestick")

hold()

segment(df.date, df.high, df.date, df.low, color='black')
rect(df.date[inc], mids[inc], w, spans[inc], fill_color="#D5E1DD", line_color="black")
rect(df.date[dec], mids[dec], …
Run Code Online (Sandbox Code Playgroud)

python bokeh

5
推荐指数
1
解决办法
5128
查看次数

如何抑制 AWS Athena 查询结果中的列标题?

我正在 S3 存储桶清单上运行 SELECT Athena 查询。然后,我想在 S3 批量操作中使用该查询的结果(.csv 格式)。

我的查询运行良好,并且我能够通过 S3 Batch 访问 .csv 输出,但由于第一行实际上是列标题,S3 Batch 会抛出不可恢复的错误,因为它认为清单现在引用多个存储桶。

如何轻松地从结果中删除列标题?我宁愿只用 SQL 来做。文件大小使得使用标准 UNIX 工具变得令人望而却步。我可以使用 AWS Glue,但这对于仅抑制 SQL 查询中的标头来说似乎有点过分了。

amazon-web-services amazon-athena

5
推荐指数
1
解决办法
3177
查看次数