简体   繁体   English

熊猫数据框:如何绘制烛台

[英]Pandas dataframe: how to plot candlesticks

I have following data in dataframe to plot candlesticks. 我在数据框中有以下数据可以绘制烛台。

     open   high    close   low
date                
2013-10-08  3.21    3.28    3.27    3.20
2013-10-09  3.25    3.28    3.26    3.22
2013-10-10  3.26    3.27    3.23    3.21
2013-10-11  3.25    3.28    3.27    3.23
2013-10-14  3.28    3.35    3.31    3.26

I tried to use candlestick_ohlc function from matplotlib.finance, but it seems that somehow I needed to change the data type of the index 'date'. 我尝试使用matplotlib.finance中的Candlestick_ohlc函数,但似乎我需要以某种方式更改索引“日期”的数据类型。 I am new to python, still trying to figure out a way. 我是python的新手,仍在尝试找出一种方法。

Any help would be appreciated, thank you. 任何帮助,将不胜感激,谢谢。

If the index is not a datetime (use df.index.dtype to find out which type it is), you can change the type to a datetime by using: 如果索引不是datetime (使用df.index.dtype找出它是哪种类型),则可以通过以下方式将类型更改为日期时间:

df.index = pd.to_datetime(df.index)

(assuming your dataframe is called df ) (假设您的数据框称为df

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM