votes up 1

key of type tuple not found and not a MultiIndex

Package:
pandas
github stars 30911
Exception Class:
KeyError

Raise code

values[key] = value
            else:
                # GH#12862 adding a new key to the Series
                self.loc[key] = value

        except TypeError as err:
            if isinstance(key, tuple) and not isinstance(self.index, MultiIndex):
                raise KeyError(
                    "key of type tuple not found and not a MultiIndex"
                ) from err

            if com.is_bool_indexer(key):
                key = check_bool_indexer(self.index, key)
                key = np.asarray(key, dtype=bool)
                try:
                
🙏 Scream for help to Ukraine
Today, 14th August 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

Ways to fix

votes up 3 votes down

Here is example:

cluster_labels=infer_cluster_labels(kmeans,Y)
X_clusters=kmeans.predict(X) #predict cluster labels/ can also use kmeans.labels_ as well
predicted_labels=infer_data_labels(X_clusters,cluster_labels)

print(X_clusters,X_clusters.shape)
print(cluster_labels)
print(predicted_labels[:20])
print(Y[:20])
Nov 14, 2021 avneeshannie answer

Add a possible fix

Please authorize to post fix