question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed

See original GitHub issue

Code Sample, a copy-pastable example if possible

samples = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data", sep=',',header=None)
varieties = pd.DataFrame(samples.iloc[:,0])
kmeans = KMeans(n_clusters = 3)
labels = kmeans.fit_predict(samples)
#setting 'labels' according to given data
labels += 1
#converting 'labels' to pandas DataFrame
labels = pd.DataFrame(labels)
df = pd.DataFrame({'labels':[labels], 'varieties':[varieties]})
ct = pd.crosstab(df['labels'],df['varieties'])

Problem description

My Dataset is like

                                          labels  \

0 0 0 2 1 2 2 2 3 2 4 3 5 …

                                       varieties  

0 0 0 1 1 1 2 1 3 1 4 1 5 …

Expected Output

output from “crosstab” function

] # TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
TomAugspurgercommented, Apr 5, 2017

You might want to ask on stackoverflow. But in general you don’t want nested data frames. The columns should just be the arrays themselves.

On Apr 5, 2017, at 12:03, aashray18521 notifications@github.com wrote:

@TomAugspurger I want to use these dataframes (labels and varieties) for ‘crosstab’ function. Please do let me know how I can do that? scikit-learn is being used by me for other tasks in the remainder of my code

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

0reactions
aashray18521commented, Apr 5, 2017

@TomAugspurger I want to use these dataframes (labels and varieties) for ‘crosstab’ function. Please do let me know how I can do that? scikit-learn is being used by me for other tasks in the remainder of my code

Read more comments on GitHub >

github_iconTop Results From Across the Web

'DataFrame' objects are mutable, thus they cannot be hashed ...
"TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed" while sorting pandas dataframe index.
Read more >
3 Ways to Solve Series Objects Are Mutable and Cannot be ...
#1 Option to Solve TypeError: Series objects are mutable and cannot be hashed ... So let's NOT use the series object as a...
Read more >
'Series' objects are mutable, thus they cannot be hashed' error ...
int is an immutable object, because you can't change it. The error saying one of your DataFrame column is a mutable object so...
Read more >
"'DataFrame' objects are mutable, thus they cannot be hashed"
This works. However, if I use "market" in place of "df_name" in the last line, then I get: TypeError: 'DataFrame' objects are mutable,...
Read more >
TypeError: 'DataFrame' objects are mutable, thus they cannot ...
Hi All, Trying to run the TabularDataBunch.from_df command to generate a DB for the tabular_learner. Upon running the code: tfms ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found