In [20]: import pandas as pd
    ...: import numpy as np
    ...:
    ...: df = pd.DataFrame(np.arange(5))

In [21]:

In [21]: df.dtypes.value_counts()
Out[21]:
int64    1
dtype: int64

.get_dtype_counts() is deprecated since version 0.25.0

Answer from bigbounty on Stack Overflow
🌐
Galaxy
help.galaxyproject.org › t › anndata-operations-attributeerror-dataframe-object-has-no-attribute-dtype › 13110
AnnData Operations - AttributeError: 'DataFrame' object has no attribute 'dtype' - single-cell - Galaxy Community Help
August 7, 2024 - Examples of the error at 60 and 73. Hello I keep encountering the above error every time that I try to work with my concatenated file. Firstly it kept coming up when trying to flag mitochondrial genes and generate QC metrics, but now it’s coming up when I try to use Scanpy NormaliseData to normalise my counts.
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)
🌐
Sololearn
sololearn.com › en › Discuss › 2237518 › unable-to-use-get_dtype_counts
Unable to use get_dtype_counts() | Sololearn: Learn to code for FREE!
April 12, 2020 - cars_data1.get_dtype_counts() Traceback (most recent call last): File " ", line 1, in cars_data1.get_dtype_counts()
🌐
Kaggle
kaggle.com › general › 108926
AttributeError: 'DataFrame' object has no attribute 'dtype' ...
Checking your browser before accessing www.kaggle.com · Click here if you are not automatically redirected after 5 seconds
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 0.25.0 › reference › api › pandas.DataFrame.get_dtype_counts.html
pandas.DataFrame.get_dtype_counts — pandas 0.25.0 documentation
Return the dtypes in this object. ... >>> a = [['a', 1, 1.0], ['b', 2, 2.0], ['c', 3, 3.0]] >>> df = pd.DataFrame(a, columns=['str', 'int', 'float']) >>> df str int float 0 a 1 1.0 1 b 2 2.0 2 c 3 3.0
🌐
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'
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 58423407 › dataframe-object-has-no-attribute-value-counts-why-is-it-happening
python - 'DataFrame' object has no attribute 'value_counts' Why is it happening? - Stack Overflow
Answer: As per the docs, extract returns DataFrame by default since expand = True by default. The correct way is to set expand = False if you want Series as output. If expand=False and pat has only one capture group, then return a Series (if ...
🌐
GitHub
github.com › scikit-learn › scikit-learn › issues › 25261
'DataFrame' object has no attribute 'dtype' · Issue #25261 · scikit-learn/scikit-learn
December 30, 2022 - packages/sklearn/preprocessing/_function_transformer.py", line 177, in _check_inverse_transform if not np.issubdtype(X.dtype, np.number): The problem is X is a Pandas DataFrame, which does not have a dtype attribute.
Author   gerardkr
🌐
GitHub
github.com › rapidsai › cuml › issues › 6183
[KeyError: 'dtype' and AttributeError: DataFrame object has no attribute dtype when using cuML's ColumnTransformer with cuDF DataFrame] · Issue #6183 · rapidsai/cuml
December 16, 2024 - Describe the bug When using cuml's ColumnTransformer with a cuDF.DataFrame as input, the function raises a KeyError: 'dtype' and subsequently an AttributeError: 'DataFrame' obje...
Author   allisond-nvidia
🌐
GitHub
github.com › pycaret › pycaret › issues › 195
AttributeError: 'DataFrame' object has no attribute 'dtype' · Issue #195 · pycaret/pycaret
June 3, 2020 - To me the pandas.DataFrame (both X and X_train) looks good. Any idea why that would crash? --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-30-0290d1b00c7f> in <module> 3 X_train, X_test = train_test_split(X, stratify=X[target_antib]) 4 ----> 5 exp_cip = setup(X_train, target_antib, feature_selection=False) ~/miniconda3/envs/py3/lib/python3.6/site-packages/pycaret/classification.py in setup(data, target, train_size, sampling, sample_estimator, categorical_features, categorical_imputation, ordinal_feature
Author   sorenwacker
🌐
KNIME Community
forum.knime.com › knime analytics platform
AttributeError: 'DataFrame' object has no attribute 'dtype' - KNIME Analytics Platform - KNIME Community Forum
April 3, 2018 - Hello, I am not able to run the script in the python(1=>1) node. The same script is working in IDE like spyder. Below is my code and attached is screenshot of the workflow and the error: import re import pandas as pd output_table = input_table.copy() head = list(output_table) reg_2013 = re.compile("(Effort_2013).") reg_2012 = re.compile("(Effort_2012).") effort_2013 = list(filter(reg_2013.match, head)) effort_2012 = list(filter(reg_2012.match, head)) colname = data = for element i...
🌐
GitHub
github.com › pandas-dev › pandas › issues › 4377
BUG: read_json -> 'DataFrame' object has no attribute 'dtype' · Issue #4377 · pandas-dev/pandas
July 27, 2013 - Came across this when creating #4376. Not sure what's going on as I was under the impression that DataFrame always has a dtype attribute. The error only seems to occur when the columns are not unique: In [5]: import pandas as pd In [6]: ...
Author   Komnomnomnom
🌐
GitHub
github.com › pandas-dev › pandas › issues › 39520
BUG: AttributeError: type object 'object' has no attribute 'dtype' with numpy 1.20.x and pandas versions 1.0.4 and earlier · Issue #39520 · pandas-dev/pandas
February 1, 2021 - /usr/local/lib/python3.8/site-packages/pandas/core/dtypes/cast.py in construct_1d_arraylike_from_scalar(value, length, dtype) 1438 else: 1439 if not isinstance(dtype, (np.dtype, type(np.dtype))): -> 1440 dtype = dtype.dtype 1441 1442 if length and is_integer_dtype(dtype) and isna(value): AttributeError: type object 'object' has no attribute 'dtype' `
Author   Lucareful