【问题标题】:Upsampling datetime - ValueError: cannot reindex a non-unique index with a method or limit上采样日期时间 - ValueError:无法使用方法或限制重新索引非唯一索引
【发布时间】:2017-12-06 04:50:07
【问题描述】:

当我尝试上采样时出现以下错误...

import pandas as pd
from datetime import date

df1=pd.read_csv("C:/Codes/test.csv")
df1['Date'] =  pd.to_datetime(df1['Date'])
df1 = df1.set_index(['Date'])
df2 = pd.DataFrame()
df2 = df1.Gen.resample('H').ffill()

我收到此错误...ValueError: cannot reindex a non-unique index with a method or limit。请指教。

我的 test.csv 是一个简单的文件,有两列包含这 5 条记录

日期|世代 ----|---- 5/1/2017|海湾 2017 年 5 月 2 日|海湾 2017 年 5 月 1 日|纳尔逊 2017 年 5 月 3 日|海湾 2017 年 5 月 4 日|纳尔逊

【问题讨论】:

    标签: indexing resampling valueerror


    【解决方案1】:

    索引必须是唯一的。您的第一条记录和第三条记录具有相同的日期“5/1/2017”,这使得无法将日期列设置为索引列。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-09
      • 1970-01-01
      • 2021-03-05
      • 2021-12-08
      • 2018-06-30
      • 1970-01-01
      • 2022-07-26
      • 1970-01-01
      相关资源
      最近更新 更多