Try df.values instead. This will have the same effect for versions of pandas prior to 0.24.0

Answer from markuscosinus on Stack Overflow
🌐
GitHub
github.com › MaxHalford › prince › issues › 101
'DataFrame' object has no attribute 'to_numpy' in Python 3.6 · Issue #101 · MaxHalford/prince
October 14, 2020 - Hey, I was trying to run the example provided in the documentation, but I am getting the following error: AttributeError: 'DataFrame' object has no attribute 'to_numpy' Here is the code: X = pd.DataFrame( data=[ ['A', 'A', 'A', 2, 5, 7, ...
Author   MaxHalford
Discussions

BUG: AttributeError: 'bool' object has no attribute 'to_numpy' in "mask_missing" method of core/missing.py
Pandas version checks I have checked that this issue has not already been reported. I have confirmed this bug exists on the latest version of pandas. I have confirmed this bug exists on the main br... More on github.com
🌐 github.com
12
May 24, 2022
python - Pandas function to_numpy - Stack Overflow
From pandas documentation, I found the function to_numpy https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_numpy.html But when I tried it(the same example as in the documentation), I have: 'DataFrame' object has no attribute 'to_numpy'. More on stackoverflow.com
🌐 stackoverflow.com
Python Coding help- keep recieving error message"AttributeError: 'numpy.ndarray' object has no attribute 'MESSAGE_A'"
You should not be accessing dataframe columns with the dot notation. This is one of the reasons why. Use uplift_df['MESSAGE_A']. More on reddit.com
🌐 r/learnpython
9
18
October 16, 2022
[QST] Error ('numpy.ndarray' object has no attribute 'to_pandas') while running MNMG Kmeans Demo Notebook
I am trying to run MNMG KMeans algorithm on a single GPU node using this notebook. I am using vanilla code. I get the following error when running the following code snippet: wait(X_cudf) X_df = to... More on github.com
🌐 github.com
1
October 11, 2020
🌐
Stack Overflow
stackoverflow.com › questions › 65055704 › attributeerror-dataframe-object-has-no-attribute-to-numpy
python - AttributeError: 'DataFrame' object has no attribute 'to_numpy' - Stack Overflow
# Convert non-numeric categorical columns to numbers c = dataframe1['prognosis'].astype('category') # assign catagories dataframe1['prognosis'] = c.cat.codes # this will change categories with codes # Extract input & outupts as numpy arrays inputs_array = dataframe1[training_inputs].to_numpy() # convert dataframe object to numpy arrays targets_array = dataframe1[training_targets].to_numpy() return inputs_array, targets_array
🌐
Data Science Learner
datasciencelearner.com › home › dataframe’ object has no attribute ‘to_numpy’ ( solved )
dataframe' object has no attribute 'to_numpy' ( Solved )
September 12, 2023 - The to_numpy method converts dataframeto numpy. Solve AttributeError: dataframe' object has no attribute 'to_numpy' error easily.
🌐
Python Forum
python-forum.io › thread-19392.html
to_numpy() works in jupyter notebook, but not in python script
Hi I am unsure why the following works in a jupyter notebook, but not in a python script that I am run from the Linux command line: #!/usr/bin/python3 import pandas as pd import numpy as np # SWAPPING COLUMNS dates=pd.date_range('1/1/2019',period...
🌐
GitHub
github.com › pandas-dev › pandas › issues › 47101
BUG: AttributeError: 'bool' object has no attribute 'to_numpy' in "mask_missing" method of core/missing.py · Issue #47101 · pandas-dev/pandas
May 24, 2022 - import pandas import numpy from qpython.qcollection import qlist res = pandas.Series(data=qlist([True, True, False, False], qtype=1, adjust_dtype=False)).replace(False, numpy.NaN) ... this expected to get an array-like object with bool elements, like [False, False, True, ...] , but when arr being an special array-like object, like the qlist object in example , the expression returns a single False, which is a bool object, thus we'll get the exception shown above · returns an array-like object instead of a bool object ... BugConstructorsSeries/DataFrame/Index/pd.array ConstructorsSeries/DataFrame/Index/pd.array ConstructorsRegressionFunctionality that used to work in a prior pandas versionFunctionality that used to work in a prior pandas versionSubclassingSubclassing pandas objectsSubclassing pandas objectsreplacereplace methodreplace method
Author   pandas-dev
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-fix-module-pandas-has-no-attribute-dataframe
How to Fix: module ‘pandas’ has no attribute ‘dataframe’ - GeeksforGeeks
December 19, 2021 - Attributes are the properties of a DataFrame that can be used to fetch data or any information related to a particular dataframe. The syntax of writing an attribute is: DataFrame_name.attribute These are the attributes of the · 11 min read How to fix AttributeError: module numpy has no attribute float' in Python
🌐
GitHub
github.com › rapidsai › cuml › issues › 2952
[QST] Error ('numpy.ndarray' object has no attribute 'to_pandas') while running MNMG Kmeans Demo Notebook · Issue #2952 · rapidsai/cuml
October 11, 2020 - [QST] Error ('numpy.ndarray' object has no attribute 'to_pandas') while running MNMG Kmeans Demo Notebook#2952
Author   rapidsai
Top answer
1 of 5
2

"sklearn.datasets" is a scikit package, where it contains a method load_iris().

load_iris(), by default return an object which holds data, target and other members in it. In order to get actual values you have to read the data and target content itself.

Whereas 'iris.csv', holds feature and target together.

FYI: If you set return_X_y as True in load_iris(), then you will directly get features and target.

from sklearn import datasets
data,target = datasets.load_iris(return_X_y=True)
2 of 5
1

The Iris Dataset from Sklearn is in Sklearn's Bunch format:

print(type(iris))
print(iris.keys())

output:

<class 'sklearn.utils.Bunch'>
dict_keys(['data', 'target', 'target_names', 'DESCR', 'feature_names', 'filename'])

So, that's why you can access it as:

x=iris.data
y=iris.target

But when you read the CSV file as DataFrame as mentioned by you:

iris = pd.read_csv('iris.csv',header=None).iloc[:,2:4]
iris.head()

output is:

    2   3
0   petal_length    petal_width
1   1.4 0.2
2   1.4 0.2
3   1.3 0.2
4   1.5 0.2

Here the column names are '1' and '2'.

First of all you should read the CSV file as:

df = pd.read_csv('iris.csv')

you should not include header=None as your csv file includes the column names i.e. the headers.

So, now what you can do is something like this:

X = df.iloc[:, [2, 3]] # Will give you columns 2 and 3 i.e 'petal_length' and 'petal_width'
y = df.iloc[:, 4] # Label column i.e 'species'

or if you want to use the column names then:

X = df[['petal_length', 'petal_width']]
y = df.iloc['species']

Also, if you want to convert labels from string to numerical format use sklearn LabelEncoder

from sklearn import preprocessing
le = preprocessing.LabelEncoder()
y = le.fit_transform(y)
🌐
Plain English
python.plainenglish.io › how-to-fix-attributeerror-in-python-6cea86059a27
How to Fix AttributeError in Python? | by JOKEN VILLANUEVA | Python in Plain English
January 27, 2025 - The “AttributeError: module ‘numpy’ has no attribute ‘object’” error occurs when there is an issue with the NumPy module, specifically the object attribute.
🌐
IncludeHelp
includehelp.com › python › dataframe-object-has-no-attribute-as_matrix.aspx
Python - 'DataFrame' object has no attribute 'as_matrix
October 5, 2023 - Now, use df.to_numpy() instead of as_matrix(). # Importing pandas package import pandas as pd # Importing numpy package import numpy as np # Creating dataframe df = pd.DataFrame(data=np.random.randint(0,50,(2,5)),columns=list('12345')) # Display original DataFrame print("Original DataFrame 1:\n",df,"\n") # using as_matrix res = df.to_numpy() # Display Result print('Result:\n',res)
🌐
Itsourcecode
itsourcecode.com › home › attributeerror: ‘dataframe’ object has no attribute ‘reshape’
[Solved] attributeerror: 'dataframe' object has no attribute 'reshape'
April 19, 2023 - ... This is the easiest way to solve this error is that you need to convert the DataFrame to a NumPy array using the “to_numpy()” method, and then apply the reshape() function to the resulting array.
🌐
GitHub
github.com › pandas-profiling › pandas-profiling › issues › 183
AttributeError: 'DataFrame' object has no attribute 'profile_report' · Issue #183 · ydataai/ydata-profiling
June 22, 2019 - AttributeError: 'DataFrame' object has no attribute 'profile_report'#183 · Copy link · Labels · bug 🐛Something isn't workingSomething isn't working · bdch1234 · opened · on Jun 22, 2019 · Issue body actions · Describe the bug Running the example in readme generates an error. To Reproduce Running: import numpy as np import pandas as pd import pandas_profiling df = pd.DataFrame( np.random.rand(100, 5), columns=['a', 'b', 'c', 'd', 'e'] ) df.profile_report() in a Jupyter notebook gives: --------------------------------------------------------------------------- AttributeError Traceback
Author   ydataai