我得到了pandas.DataFrame df:
打开高低关闭量索引日期设置
0 107.390 107.402 107.389 107.402 190.099998 0 0.0 -1
1 107.190 107.275 107.187 107.265 1419.299994 1 1.0 1
2 107.272 107.272 107.255 107.256 174.000000 2 2.0 -1
3 107.255 107.255 107.185 107.255 2581.300001 3 3.0 -1
4 107.199 107.258 107.185 107.245 4102.199995 4 4.0 -1
5 107.195 107.258 107.185 107.250 3335.600000 5 5.0 1
6 107.242 107.258 107.185 107.248 2824.900019 6 6.0 -1
7 107.343 107.345 107.187 107.245 1291.600012 7 7.0 -1
8 107.195 107.265 107.180 107.251 2746.099976 8 8.0 1
然后我从数据框中选择子集:
dfs = df.loc [df [' setup'] == 1]
当我尝试使用Plotly和dfs绘制绘图时,它显示错误,但它适用于df。
fig = FF.create_candlestick(dfs [' Open'],dfs [' High'],dfs [' Low'],dfs ['] ;关闭'],日期= dfs ['索引'])
追踪(最近一次通话): File" C:/ Users / Qiu / Desktop / FX Programming / H1Signals.py",102行in fig = FF.create_candlestick(dfs [' Open'],dfs [' High'],dfs [' Low'],dfs ['关闭&# 39;],dates = dfs [' index']) 文件" C:\ Users \ Qiu \ Anaconda3 \ lib \ site-packages \ plotly \ tools.py",第5810行,在create_candlestick中 ** kwargs) 文件" C:\ Users \ Qiu \ Anaconda3 \ lib \ site-packages \ plotly \ tools.py",第4973行,在_validate_ohlc 如果高[指数]< LST [指数]: 文件" C:\ Users \ Qiu \ Anaconda3 \ lib \ site-packages \ pandas \ core \ series.py",第583行, getitem result = self.index.get_value(self,key) 文件" C:\ Users \ Qiu \ Anaconda3 \ lib \ site-packages \ pandas \ indexes \ base.py",1980行,get_value tz = getattr(series.dtype,' tz',None)) 文件" pandas \ index.pyx",第103行,在pandas.index.IndexEngine.get_value(pandas \ index.c:3332) 文件" pandas \ index.pyx",第111行,在pandas.index.IndexEngine.get_value(pandas \ index.c:3035) 文件" pandas \ index.pyx",第159行,在pandas.index.IndexEngine.get_loc(pandas \ index.c:4018) 文件" pandas \ hashtable.pyx",第303行,在pandas.hashtable.Int64HashTable.get_item(pandas \ hashtable.c:6610) 文件" pandas \ hashtable.pyx",第309行,在pandas.hashtable.Int64HashTable.get_item(pandas \ hashtable.c:6554) KeyError:0
答案 0 :(得分:0)
尝试:
dfs = df.loc[df['setup'] == 1]
dfs = dfs.reset_index()
fig = FF.create_candlestick(dfs['Open'], dfs['High'], dfs['Low'], dfs['Close'], dates=dfs['index'])
当您使用条件选择来拼接数据帧时,它会保留其原始索引。 Plotly后端代码尝试以线性方式遍历索引,因此可能会中断。但是,这可能会添加名为“index”或“unnamed:0”的列。因此,请确保在绘制之前没有两列名为“index”的列。希望这可以帮助。