简体   繁体   English

ValueError:无法处理非唯一的多索引! 即使我们有唯一索引

[英]ValueError: cannot handle a non-unique multi-index! even when we have unique index

I asked a question last days and I got the accepted response for that.前几天我问了一个问题,我得到了接受的答复。 Here is the question,这是问题,

Group the dataframe based on ids and stick the values of ids to each other with mean of the last days 根据 ids 对 dataframe 进行分组,并将 ids 的值与最后几天的平均值相互粘贴

But, the problem is that when I want to apply this code to a large dataframe, it gives me an error as ValueError: cannot handle a non-unique multi-index!但是,问题是当我想将这段代码应用到一个大的 dataframe 时,它给我一个错误ValueError: cannot handle a non-unique multi-index! . . I've tried to check the index of my data frame by df.columns.value_counts() and as follow, all of the count for my dataframe is 1 .我试图通过df.columns.value_counts()检查我的数据框的索引,如下所示,我的 dataframe 的所有计数都是1 my dataframe has 30 columns with 3000 rows.我的 dataframe 有 30 列 3000 行。 point_id, date, and Temperatures are columns. point_id、date 和 Temperatures是列。

在此处输入图像描述

Does anybody know how to solve this problem?有人知道如何解决这个问题吗? Thank you so much.太感谢了。

You have 254 rows where you have at least 2 data points for the same (point_id, date).您有 254 行,其中至少有 2 个相同的数据点(point_id,日期)。 What do you want to do with records for a same (point_id, date)?您想对相同 (point_id, date) 的记录做什么? You can group this data and keep the mean, for instance.例如,您可以对这些数据进行分组并保留平均值。

Here is the list:这是列表:

df = pd.read_csv('dft.csv', index_col=0)
counts = df.value_counts(['point_id', 'date'], sort=False).loc[lambda x: x > 1]

暂无
暂无

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

相关问题 Pandas ValueError:尝试重新索引时无法处理非唯一多索引 - Pandas ValueError: cannot handle a non-unique multi-index when trying to re-index ValueError:无法处理非唯一的多索引。 添加列后使用 .loc 或 set_index 时 - ValueError: cannot handle a non-unique multi-index! when using .loc or .set_index after adding a column ValueError:无法处理非唯一的多索引! 尝试将来自多个数据帧的列合并到一个 dataframe - ValueError: cannot handle a non-unique multi-index! When trying to combine columns from multiple dataframes in to one dataframe 需要处理具有非唯一多索引的串联数据帧 - Need to handle a concatenated dataframe with non-unique multi-index 获取 ValueError - 在 Pandas 中使用 expand() 时出现非唯一多索引 - Getting ValueError - non-unique multi-index when using explode() in Pandas pandas.concat:无法处理非唯一的多索引! 熊猫蟒 - pandas.concat: Cannot handle a non-unique multi-index! Pandas Python 这是什么意思? xarray 错误:无法处理非唯一的多索引 - what does this mean? xarray error: cannot handle a non-unique multi-index Dataframe.loc 返回字典或 Dataframe [已解决](无法处理非唯一的多索引!) - Dataframe.loc returns dictionary or a Dataframe [Solved] (Cannot handle a non-unique multi-index!) 错误无法处理 groupby 子句中的非唯一多索引是什么意思? - What is the meaning of the error cannot handle a non-unique multi index in groupby clause? 如何合并/合并/加入 2 个具有非唯一多索引的数据帧以协调内容? - how to merge/concat/join 2 dataframes with a non-unique multi-index to reconcile the content?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM