[英]ValueError in time series data
I Have the following code:我有以下代码:
import fxcmpy
import pandas as pd
from pandas import datetime
from pandas import DataFrame as df
import matplotlib
from pandas_datareader import data as web
import matplotlib.pyplot as plt
import datetime
from datetime import date
import numpy as np
TOKEN = "hidden "
con = fxcmpy.fxcmpy(access_token=TOKEN, log_level='error')
print(con.get_instruments())
symbols = con.get_instruments()
ticker = 'JPYBasket'
start = datetime.datetime(2008,1,1)
end = datetime.datetime.today()
today = date.today()
start1 = datetime.datetime(2019,1,1)
data = con.get_candles(ticker, period='D1', start = start, end = end)
data1 = con.get_candles(ticker, period='D1', start = start1, end = end)
data.index = pd.to_datetime(data.index, format ='%Y-%m-%d')
data1.index = pd.to_datetime(data1.index, format ='%Y-%m-%d')
for some reason i am getting the following error:由于某种原因,我收到以下错误:
ValueError: cannot reindex from a duplicate axis
I am not getting the value error if i say use EUR/USD but only when i try 'EMBasket', 'JPYBasket' i get this error!如果我说使用欧元/美元,我不会收到价值错误,但只有当我尝试“EMBasket”、“JPYBasket”时,我才会收到此错误!
-- JPYBasket : -- 日元篮子:
data output is :
bidopen bidclose bidhigh bidlow askopen askclose askhigh asklow tickqty
date
2019-04-25 9720 9710 9714 9710 9723 9718 9719 9714 2363
2019-04-26 9720 9720 9720 9720 9723 9723 9723 9723 0
2019-04-26 9710 9698 9729 9679 9718 9708 9732 9686 74942
2019-04-29 9698 9679 9701 9661 9708 9683 9708 9664 66167
2019-04-30 9679 9669 9721 9666 9683 9674 9723 9668 72255
... ... ... ... ... ... ... ... ... ...
2019-12-19 9869 9889 9904 9849 9875 9893 9907 9852 75057
2019-12-20 9889 9888 9904 9879 9893 9897 9907 9882 72982
2019-12-23 9888 9896 9911 9880 9897 9901 9914 9883 73520
2019-12-24 9896 9898 9908 9894 9901 9907 9911 9897 64976
2019-12-26 9898 9851 9881 9846 9907 9856 9884 9849 40177
177 rows × 9 columns
and data1
output is:和data1
输出是:
bidopen bidclose bidhigh bidlow askopen askclose askhigh asklow tickqty
date
2019-04-25 9720 9710 9714 9710 9723 9718 9719 9714 2363
2019-04-26 9720 9720 9720 9720 9723 9723 9723 9723 0
2019-04-26 9710 9698 9729 9679 9718 9708 9732 9686 74942
2019-04-29 9698 9679 9701 9661 9708 9683 9708 9664 66167
2019-04-30 9679 9669 9721 9666 9683 9674 9723 9668 72255
... ... ... ... ... ... ... ... ... ...
2019-12-19 9869 9889 9904 9849 9875 9893 9907 9852 75057
2019-12-20 9889 9888 9904 9879 9893 9897 9907 9882 72982
2019-12-23 9888 9896 9911 9880 9897 9901 9914 9883 73520
2019-12-24 9896 9898 9908 9894 9901 9907 9911 9897 64976
2019-12-26 9898 9851 9881 9846 9907 9856 9884 9849 40177
177 rows × 9 columns
Your script is missing the operations you perform on the data-matrices.您的脚本缺少您对数据矩阵执行的操作。 Please update question to see what operations are performed on the matrices.请更新问题以查看对矩阵执行的操作。
A little search on the internet for ValueError: cannot reindex from a duplicate axis
here at A and here at B points in the direction of duplicate values in axis columns in your dataset prior or after operation.在互联网上稍微搜索一下ValueError: cannot reindex from a duplicate axis
A ValueError: cannot reindex from a duplicate axis
和B处ValueError: cannot reindex from a duplicate axis
指向操作之前或之后数据集中轴列中重复值的方向。
For example from (B) see below.例如从(B)见下文。
Timestamp A B C ...
2014-11-09 00:00:00 NaN 1 NaN NaN
2014-11-09 00:00:00 2 NaN NaN NaN
2014-11-09 00:00:00 NaN NaN 3 NaN
2014-11-09 08:24:00 NaN NaN 1 NaN
2014-11-09 08:24:00 105 NaN NaN NaN
2014-11-09 09:19:00 NaN NaN 23 NaN
Although the data is different for:虽然数据不同的是:
2014-11-09 08:24:00 NaN NaN 1 NaN
2014-11-09 08:24:00 105 NaN NaN NaN
Their column name is in both cases 2014-11-09 08:24:00
, which is not permitted.他们的列名在两种情况下都是2014-11-09 08:24:00
,这是不允许的。 And thus ValueError: cannot reindex from a duplicate axis
is raised as an error.因此ValueError: cannot reindex from a duplicate axis
作为错误引发。 This, off course, can also happen in column-names.当然,这也可能发生在列名中。
To be specific in your case:具体到您的情况:
The row label 2019-04-26
is there at least twice in your example data.行标签2019-04-26
在您的示例数据中至少出现两次。 What you can do is extend the label or look into it how the label looks while in EUR.您可以做的是扩展标签或查看标签在欧元中的外观。 And then look at the operation that changes the row-label name when you convert the datas to Yen.然后查看将数据转换为日元时更改行标签名称的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.