简体   繁体   中英

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!

-- 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:

    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.

For example from (B) see below.

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. And thus ValueError: cannot reindex from a duplicate axis is raised as an error. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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