I got the following error : 'DataFrame' object has no attribute 'data' I am trying to get the 'data' and the 'target' of the iris setosa database, but I can't. For example, when I load the iris setosa directly from sklearn datasets I get a good result:

Program:

from sklearn import datasets
import numpy as np
iris = datasets.load_iris()
X = iris.data[:, [2, 3]]
y = iris.target
print('Class labels:', np.unique(y))


output:

Class labels: [0 1 2]


But if I try to load it directly from extension '.csv' I get the following error:

Program:

import pandas as pd

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

x = iris.data
y = iris.target


output:

'DataFrame' object has no attribute 'data'


Why does this happen?
"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)