[英]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.