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   ftatarli
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 - AttributeError: 'DataFrame' object has no attribute 'to_numpy' - Stack Overflow
------------------------------... object to numpy arrays 11 targets_array = dataframe1[training_targets].to_numpy() 12 return inputs_array, targets_array ~\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name) 3079 3080 .. versionchanged:: 1.1.0 -> 3081 3082 Passing compression options as keys in dict is 3083 supported for compression modes 'gzip' and 'bz2' AttributeError: 'DataFrame' ... More on stackoverflow.com
🌐 stackoverflow.com
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 - How to fix AttributeError: 'Series' object has no attribute 'to_numpy' - Stack Overflow
AttributeError: 'Series' object has no attribute 'to_numpy' More on stackoverflow.com
🌐 stackoverflow.com
🌐
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
Published   May 24, 2022
Author   rainnnnny
🌐
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.
Find elsewhere
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)
🌐
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   aamirshafi
🌐
Edureka Community
edureka.co › community › 42320 › python-pandas-attributeerror-dataframe-object-attribute
Python Pandas error AttributeError DataFrame object has ...
March 28, 2019 - Host '172.31.27.232' is blocked because of many connection errors; unblock with 'mariadb-admin flush-hosts'
🌐
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.
🌐
GitHub
github.com › automl › auto-sklearn › issues › 254
AttributeError: 'DataFrame' object has no attribute 'toarray' · Issue #254 · automl/auto-sklearn
March 21, 2017 - Traceback (most recent call last): ... 55, in transform return X.toarray() File "/home/foo/test/env3/lib/python3.4/site-packages/pandas/core/generic.py", line 2744, in __getattr__ return object.__getattribute__(self, name) AttributeError: 'DataFrame' object has no attribute ...
Author   sovaa
🌐
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)