我第一次使用plotly,当我尝试绘制股票数据框时,该图确实很奇怪:
这是我的数据框:
AAPL AMZN
Date
2008-12-31 10.681297 51.279999
2009-02-01 11.357091 54.360001
2009-05-01 11.836406 54.060001
2009-06-01 11.641174 57.360001
2009-07-01 11.389630 56.200001
代码:
import cufflinks as cf
cf.go_offline()
stocks['AAPL'].iplot()
我的数据框信息
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 2657 entries, 2008-12-31 to 2019-07-23
Data columns (total 2 columns):
AMZN 2657 non-null float64
AAPL 2657 non-null float64
dtypes: float64(2)
memory usage: 62.3 KB
答案 0 :(得分:0)
IIUC,您试图绘制在一个列上,即列。您可以尝试绘制整个DataFrame
到目前为止我尝试过的,
import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.random((200,3)))
df['date'] = pd.date_range('2000-1-1', periods=200, freq='D')
df = df.set_index(['date'])
df.info()
输出:
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 200 entries, 2000-01-01 to 2000-07-18
Data columns (total 3 columns):
0 200 non-null float64
1 200 non-null float64
2 200 non-null float64
dtypes: float64(3)
memory usage: 6.2 KB
我们的数据框是什么样的
df.head()
输出
0 1 2
date
2000-01-01 0.537956 0.575147 0.146626
2000-01-02 0.504606 0.309531 0.715763
2000-01-03 0.517008 0.591016 0.227111
2000-01-04 0.088941 0.702333 0.975861
2000-01-05 0.956740 0.627588 0.249751
然后是情节
df.iplot()