gpt4 book ai didi

python - 时间序列数据中的 ValueError

转载 作者:行者123 更新时间:2023-12-04 18:55:12 28 4
gpt4 key购买 nike

我有以下代码:

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')

由于某种原因,我收到以下错误:
ValueError: cannot reindex from a duplicate axis

如果我说使用欧元/美元,我不会收到值(value)错误,但只有当我尝试“EMBasket”、“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

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

最佳答案

您的脚本缺少您对数据矩阵执行的操作。请更新问题以查看对矩阵执行的操作。

在互联网上搜索 ValueError: cannot reindex from a duplicate axis here at Ahere at B在操作之前或之后指向数据集中轴列中重复值的方向。

例如从(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

虽然数据不同的是:
2014-11-09 08:24:00                     NaN    NaN     1     NaN         
2014-11-09 08:24:00 105 NaN NaN NaN

他们的列名在这两种情况下都是 2014-11-09 08:24:00 ,这是不允许的。因此 ValueError: cannot reindex from a duplicate axis作为错误引发。当然,这也可能发生在列名中。

具体到您的情况:

行标签 2019-04-26您的示例数据中是否至少有两次。您可以做的是扩展标签或查看标签在欧元中的外观。然后查看将数据转换为日元时更改行标签名称的操作。

关于python - 时间序列数据中的 ValueError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59528691/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com