TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed
See original GitHub issueCode 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:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
@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