简体   繁体   English

为什么我会为一组骑行数据得到这个值错误,即使它对于不同的骑行非常有效

[英]Why am I getting this valueerror for one set of ride data even though it works perfectly for a different ride

Hi there I am getting this:嗨,我得到了这个:

ValueError: cannot reindex a non-unique index with a method or limit

when running these lines:运行这些行时:

df_nemo_all = pd.read_csv(
    "https://cdn.touringplans.com/datasets/finding_nemo_subs.csv", usecols=['date','datetime','SPOSTMIN'], 
    parse_dates=['date', 'datetime']
)
df_nemo_all['ride'] = 'space'
df_nemo_all['open'] = ~((df_space_all['SPOSTMIN'] == -999))

df_nemo = df_nemo_all.set_index('datetime').sort_index()
df_nemo = df_nemo.loc['2017-01-01 06:00':'2017-02-01 00:00']
df_nemo = df_nemo.resample('15Min').ffill()

when it works for a different ride such as:当它适用于不同的骑行时,例如:

df_space_all = pd.read_csv(
    "https://cdn.touringplans.com/datasets/space_mountain_dlr.csv", usecols=['date','datetime','SPOSTMIN'], 
    parse_dates=['date', 'datetime']
)
df_space_all['ride'] = 'space'
df_space_all['open'] = ~((df_space_all['SPOSTMIN'] == -999))

df_space = df_space_all.set_index('datetime').sort_index()
df_space = df_space.loc['2017-01-01 06:00':'2017-02-01 00:00']
df_space = df_space.resample('15Min').ffill()

You do have duplicates in your index您的索引中确实有重复项

  1. 2017-01-13 09:31:05 has two rows 2017-01-13 09:31:05 有两排
  2. I've excluded this and then it works我已经排除了这个,然后它就可以工作了
df_space_all = pd.read_csv(
    "https://cdn.touringplans.com/datasets/space_mountain_dlr.csv", usecols=['date','datetime','SPOSTMIN'], 
    parse_dates=['date', 'datetime']
)
df_space_all['ride'] = 'space'
df_space_all['open'] = ~((df_space_all['SPOSTMIN'] == -999))

df_space = df_space_all.set_index('datetime').sort_index()
df_space = df_space.loc['2017-01-01 06:00':'2017-02-01 00:00']
df_space = df_space.resample('15Min').ffill()

df_nemo_all = pd.read_csv(
    "https://cdn.touringplans.com/datasets/finding_nemo_subs.csv", usecols=['date','datetime','SPOSTMIN'], 
    parse_dates=['date', 'datetime']
)
df_nemo_all['ride'] = 'space'
df_nemo_all['open'] = ~((df_space_all['SPOSTMIN'] == -999))

df_nemo = df_nemo_all.set_index('datetime').sort_index()
df_nemo = df_nemo.loc['2017-01-01 06:00':'2017-02-01 00:00']
c = df_nemo.groupby(level=0).transform("count")
c[c["date"]>1].index.tolist()
df_nemo = df_nemo[~df_nemo.index.isin(c[c["date"]>1].index.tolist())].resample('15Min').ffill()
df_nemo

output output

    date    SPOSTMIN    ride    open
datetime                
2017-01-01 09:00:00 NaT NaN NaN NaN
2017-01-01 09:15:00 2017-01-01  5.0 space   True
2017-01-01 09:30:00 2017-01-01  5.0 space   True
2017-01-01 09:45:00 2017-01-01  5.0 space   True
2017-01-01 10:00:00 2017-01-01  5.0 space   True
... ... ... ... ...
2017-01-31 18:45:00 2017-01-31  20.0    space   True
2017-01-31 19:00:00 2017-01-31  20.0    space   True
2017-01-31 19:15:00 2017-01-31  20.0    space   True
2017-01-31 19:30:00 2017-01-31  10.0    space   True
2017-01-31 19:45:00 2017-01-31  10.0    space   True

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在Robot Framework IDE(RIDE)中使用pymssql连接到db会出现错误? - Why I am getting error by connecting to db using pymssql in Robot Framework IDE (RIDE)? 为什么我在页面上找到了StaleElementReferenceException,但仍然找到了该元素? - Why am I getting a StaleElementReferenceException even though it found the element on the page? 为什么我得到这个 ValueError - Why am i getting this ValueError 为什么会收到此ValueError? - Why am I getting this ValueError? 为什么即使我不访问此文件夹也会收到此错误? - Why am I getting this error even though I don't even access this folder? 即使我正确初始化,为什么会出现“ cuMemAlloc失败:未初始化”的信息? - Why am I getting 'cuMemAlloc failed: not initialized' even though I am initializing correctly? 为什么即使我只是在定义一个变量,也会收到 UnboundLocalError? - Why am I getting an UnboundLocalError even though I am just defining a variable? "为什么我收到一个错误,指出未定义 k,即使我已返回它?" - Why am I getting an error stated that k is not defined, even though i have returned it? 即使我正确输入了所有内容,我也无法理解为什么我会收到元组错误 - Can't understand why I am getting tuple error even though I typed everything correctly 为什么我得到 IndexError: list index out of range 错误,即使我有一个正确的列表 - Why am I getting IndexError: list index out of range error even though I have a proper list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM