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.

MCA : 'SparseDataFrame' object has no attribute 'to_numpy'

See original GitHub issue

I’m trying to execute the following code -

import prince
mca = prince.MCA(n_components=10,n_iter=5,copy=True,check_input=True,engine='auto',random_state=10)
mca_model=mca.fit(df_sample)

The problem is that OneHotEncoder has sparse set to True, so it returns a sparse dataframe. But the fit function has the following piece of code -

if isinstance(X, pd.DataFrame):
            X = X.to_numpy()

But to_numpy cannot be applied to sparse dataframes. As a result I’m getting the following error-

AttributeError: ‘SparseDataFrame’ object has no attribute ‘to_numpy’

Not sure if this is a bug or if i’m doing something wrong.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
MaxHalfordcommented, Apr 23, 2019

Yep, got it.

I’m on holiday at the moment, but I’ll work on it when I get back in ~10 days.

1reaction
DerpMindcommented, Feb 5, 2020

No, sorry. You are right - I got it working now with an older version of pandas. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix AttributeError: 'Series' object has no attribute ...
Check the version of your pandas library: import pandas print(pandas.__version__). If your version is less than 0.24.1:
Read more >
dataframe' object has no attribute 'to_numpy' ( Solved )
Suppose you want to convert the dataframe to numpy and you are getting dataframe' object has no attribute 'to_numpy' error then how you...
Read more >
Sparse data structures — pandas 1.5.2 documentation
The SparseDataFrame.default_kind and SparseDataFrame.default_fill_value attributes have no replacement. Interaction with scipy.sparse ...
Read more >
[QST] Error ('numpy.ndarray' object has no attribute ... - GitHub
I am trying to run MNMG KMeans algorithm on a single GPU node using this notebook. I am using vanilla code. I get...
Read more >
Python - 'DataFrame' object has no attribute 'as_matrix
DataFrames consist of rows, columns, and data. The as_matrix() method was used to return a NumPy array, this NumPy array is created when...
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