Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas DF dtype attribute

Tags:

python

pandas

When calling the dtypes attribute on a pandas data frame, the last line of the output is usually dtype: object. For example:

In [1]: import pandas as pd
In [2]: df = pd.DataFrame({'numbers':100,'floats': 5.75,'name':'Jill'},index=['a'])
In [3]: df.dtypes
Out[3]: 
numbers  int64
floats float64
name    object
dtype: object

What is the dtype: object line referring to in the output?

like image 764
jgg Avatar asked Nov 24 '25 10:11

jgg


1 Answers

pandas.DataFrame.dtypes is a pd.Series object, so that's just the dtype of the Series that holds your dtypes!

>>> type(df.dtypes)
<class 'pandas.core.series.Series'>

That makes sense, since it holds numpy.dtype objects:

>>> df.dtypes.map(type)
numbers    <class 'numpy.dtype'>
floats     <class 'numpy.dtype'>
name       <class 'numpy.dtype'>
dtype: object
like image 190
juanpa.arrivillaga Avatar answered Nov 27 '25 01:11

juanpa.arrivillaga



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!