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

Viewed 141

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

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!. 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. my dataframe has 30 columns with 3000 rows. point_id, date, and Temperatures are columns.

enter image description here

Does anybody know how to solve this problem? Thank you so much.

1 Answers

You have 254 rows where you have at least 2 data points for the same (point_id, date). What do you want to do with records for a same (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]
Related