It means:

Copy'O'     (Python) objects

Source.

The first character specifies the kind of data and the remaining characters specify the number of bytes per item, except for Unicode, where it is interpreted as the number of characters. The item size must correspond to an existing type, or an error will be raised. The supported kinds are to an existing type, or an error will be raised. The supported kinds are:

Copy'b'       boolean
'i'       (signed) integer
'u'       unsigned integer
'f'       floating-point
'c'       complex-floating point
'O'       (Python) objects
'S', 'a'  (byte-)string
'U'       Unicode
'V'       raw data (void)

Another answer helps if need check types.

Answer from jezrael on Stack Overflow
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.dtypes.html
pandas.DataFrame.dtypes — pandas 3.0.3 documentation
>>> df = pd.DataFrame( ... { ... "float": [1.0], ... "int": [1], ... "datetime": [pd.Timestamp("20180310")], ... "string": ["foo"], ... } ... ) >>> df.dtypes float float64 int int64 datetime datetime64[us] string str dtype: object
Top answer
1 of 5
211

It means:

Copy'O'     (Python) objects

Source.

The first character specifies the kind of data and the remaining characters specify the number of bytes per item, except for Unicode, where it is interpreted as the number of characters. The item size must correspond to an existing type, or an error will be raised. The supported kinds are to an existing type, or an error will be raised. The supported kinds are:

Copy'b'       boolean
'i'       (signed) integer
'u'       unsigned integer
'f'       floating-point
'c'       complex-floating point
'O'       (Python) objects
'S', 'a'  (byte-)string
'U'       Unicode
'V'       raw data (void)

Another answer helps if need check types.

2 of 5
66

When you see dtype('O') inside dataframe this means Pandas string.

What is dtype?

Something that belongs to pandas or numpy, or both, or something else? If we examine pandas code:

Copydf = pd.DataFrame({'float': [1.0],
                    'int': [1],
                    'datetime': [pd.Timestamp('20180310')],
                    'string': ['foo']})
print(df)
print(df['float'].dtype,df['int'].dtype,df['datetime'].dtype,df['string'].dtype)
df['string'].dtype

It will output like this:

Copy   float  int   datetime string    
0    1.0    1 2018-03-10    foo
---
float64 int64 datetime64[ns] object
---
dtype('O')

You can interpret the last as Pandas dtype('O') or Pandas object which is Python type string, and this corresponds to Numpy string_, or unicode_ types.

CopyPandas dtype    Python type     NumPy type          Usage
object          str             string_, unicode_   Text

Like Don Quixote is on ass, Pandas is on Numpy and Numpy understand the underlying architecture of your system and uses the class numpy.dtype for that.

Data type object is an instance of numpy.dtype class that understand the data type more precise including:

  • Type of the data (integer, float, Python object, etc.)
  • Size of the data (how many bytes is in e.g. the integer)
  • Byte order of the data (little-endian or big-endian)
  • If the data type is structured, an aggregate of other data types, (e.g., describing an array item consisting of an integer and a float)
  • What are the names of the "fields" of the structure
  • What is the data-type of each field
  • Which part of the memory block each field takes
  • If the data type is a sub-array, what is its shape and data type

In the context of this question dtype belongs to both pands and numpy and in particular dtype('O') means we expect the string.


Here is some code for testing with explanation: If we have the dataset as dictionary

Copyimport pandas as pd
import numpy as np
from pandas import Timestamp

data={'id': {0: 1, 1: 2, 2: 3, 3: 4, 4: 5}, 'date': {0: Timestamp('2018-12-12 00:00:00'), 1: Timestamp('2018-12-12 00:00:00'), 2: Timestamp('2018-12-12 00:00:00'), 3: Timestamp('2018-12-12 00:00:00'), 4: Timestamp('2018-12-12 00:00:00')}, 'role': {0: 'Support', 1: 'Marketing', 2: 'Business Development', 3: 'Sales', 4: 'Engineering'}, 'num': {0: 123, 1: 234, 2: 345, 3: 456, 4: 567}, 'fnum': {0: 3.14, 1: 2.14, 2: -0.14, 3: 41.3, 4: 3.14}}
df = pd.DataFrame.from_dict(data) #now we have a dataframe

print(df)
print(df.dtypes)

The last lines will examine the dataframe and note the output:

Copy   id       date                  role  num   fnum
0   1 2018-12-12               Support  123   3.14
1   2 2018-12-12             Marketing  234   2.14
2   3 2018-12-12  Business Development  345  -0.14
3   4 2018-12-12                 Sales  456  41.30
4   5 2018-12-12           Engineering  567   3.14
id               int64
date    datetime64[ns]
role            object
num              int64
fnum           float64
dtype: object

All kind of different dtypes

Copydf.iloc[1,:] = np.nan
df.iloc[2,:] = None

But if we try to set np.nan or None this will not affect the original column dtype. The output will be like this:

Copyprint(df)
print(df.dtypes)

    id       date         role    num   fnum
0  1.0 2018-12-12      Support  123.0   3.14
1  NaN        NaT          NaN    NaN    NaN
2  NaN        NaT         None    NaN    NaN
3  4.0 2018-12-12        Sales  456.0  41.30
4  5.0 2018-12-12  Engineering  567.0   3.14
id             float64
date    datetime64[ns]
role            object
num            float64
fnum           float64
dtype: object

So np.nan or None will not change the columns dtype, unless we set the all column rows to np.nan or None. In that case column will become float64 or object respectively.

You may try also setting single rows:

Copydf.iloc[3,:] = 0 # will convert datetime to object only
df.iloc[4,:] = '' # will convert all columns to object

And to note here, if we set string inside a non string column it will become string or object dtype.

🌐
Practical Business Python
pbpython.com › pandas_dtypes.html
Overview of Pandas Data Types - Practical Business Python
Customer Number float64 Customer Name object 2016 object 2017 object Percent Growth object Jan Units object Month int64 Day int64 Year int64 Active bool dtype: object · Whether you choose to use a lambda function, create a more standard python function or use another approach like np.where() , these approaches are very flexible and can be customized for your own unique data needs. Pandas has a middle ground between the blunt astype() function and the more complex custom functions.
Top answer
1 of 4
208

The dtype object comes from NumPy, it describes the type of element in a ndarray. Every element in an ndarray must have the same size in bytes. For int64 and float64, they are 8 bytes. But for strings, the length of the string is not fixed. So instead of saving the bytes of strings in the ndarray directly, Pandas uses an object ndarray, which saves pointers to objects; because of this the dtype of this kind ndarray is object.

Here is an example:

  • the int64 array contains 4 int64 value.
  • the object array contains 4 pointers to 3 string objects.

2 of 4
78

@HYRY's answer is great. I just want to provide a little more context..

Arrays store data as contiguous, fixed-size memory blocks. The combination of these properties together is what makes arrays lightning fast for data access. For example, consider how your computer might store an array of 32-bit integers, [3,0,1].

If you ask your computer to fetch the 3rd element in the array, it'll start at the beginning and then jump across 64 bits to get to the 3rd element. Knowing exactly how many bits to jump across is what makes arrays fast.

Now consider the sequence of strings ['hello', 'i', 'am', 'a', 'banana']. Strings are objects that vary in size, so if you tried to store them in contiguous memory blocks, it'd end up looking like this.

Now your computer doesn't have a fast way to access a randomly requested element. The key to overcoming this is to use pointers. Basically, store each string in some random memory location, and fill the array with the memory address of each string. (Memory addresses are just integers.) So now, things look like this

Now, if you ask your computer to fetch the 3rd element, just as before, it can jump across 64 bits (assuming the memory addresses are 32-bit integers) and then make one extra step to go fetch the string.

The challenge for NumPy is that there's no guarantee the pointers are actually pointing to strings. That's why it reports the dtype as 'object'.

Shamelessly gonna plug my own course on NumPy where I originally discussed this.

🌐
Kaggle
kaggle.com › questions-and-answers › 215448
What exactly an "object" dtype refers to? | Kaggle
It's an unfortunate side-effect ... As you are probably already aware, Pandas does have a category dtype, but to make use of it, you have to typecast the column into that format....
🌐
Kaggle
kaggle.com › general › 188478
What is the difference between Pandas Object & String dtype ? | Kaggle
When you import data into a Pandas DataFrame, Pandas by default tries to know the data types of each column. However, the columns with text are by default marked as Object datatype.💡 · But Object dtype have a much broader scope.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.api.types.is_object_dtype.html
pandas.api.types.is_object_dtype — pandas 3.0.3 documentation
Whether or not the array-like or dtype is of the object dtype. ... Check whether the provided array or dtype is of a numeric dtype. ... Check whether the provided array or dtype is of the string dtype. ... Check whether the provided array or dtype is of a boolean dtype. ... >>> from pandas.api.types import is_object_dtype >>> is_object_dtype(object) True >>> is_object_dtype(int) False >>> is_object_dtype(np.array([], dtype=object)) True >>> is_object_dtype(np.array([], dtype=int)) False >>> is_object_dtype([1, 2, 3]) False
🌐
Statology
statology.org › home › the complete guide to pandas dtypes
The Complete Guide to Pandas dtypes
April 11, 2024 - Lastly, we can use the following syntax to display the data type of each column in the pandas DataFrame: #display data type of each column in DataFrame df.dtypes team object points int64 assists int64 minutes float64 all_star bool dtype: object
Find elsewhere
🌐
Reddit
reddit.com › r/kaggle › [question] what is the significance of dtype == 'object'?
r/kaggle on Reddit: [Question] What is the significance of dtype == 'object'?
August 11, 2022 -

Following a Kaggle tutorial where the data set is the melbourne housing data.

I keep seeing this:

categorical_cols = [cname for cname in X_train_full.columns if X_train_full[cname].nunique() < 10 and 
                        X_train_full[cname].dtype == "object"]

I understand that we're concerned about columns that have data with low cardinality. I'm confused why we care that the dtype == 'object'. Why does this matter? How does the dtype improve our ability to predict pricing?

🌐
Codegive
codegive.com › blog › pandas_object_dtype.php
Pandas Object Dtype (2024): Master Its Secrets & Unlock Peak Data Performance
Pandas object dtype is a flexible catch-all data type used to store a variety of Python objects, most commonly strings, but also mixed numerical types, booleans, lists, dictionaries, or custom objects within a Series or DataFrame column. It acts as a pointer to Python objects, allowing for ...
🌐
Pandas
pandas.pydata.org › docs › dev › reference › api › pandas.DataFrame.dtypes.html
pandas.DataFrame.dtypes — pandas 3.1.0.dev0+974.ge652ee88a5 documentation
>>> df = pd.DataFrame( ... { ... "float": [1.0], ... "int": [1], ... "datetime": [pd.Timestamp("20180310")], ... "string": ["foo"], ... } ... ) >>> df.dtypes float float64 int int64 datetime datetime64[us] string str dtype: object
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to retrieve the dtype object in pandas
5 Best Ways to Retrieve the Dtype Object in Pandas - Be on the Right Side of Change
March 2, 2024 - It returns the dtype object of the single-dimensional, homogeneously-typed array. For a given pandas series, series.dtype will disclose the dtype of the underlying data effectively.
🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: How to use astype() to cast dtype of DataFrame | note.nkmk.me
August 9, 2023 - pandas.Series has a single data type (dtype), while pandas.DataFrame can have a different data type for each column. You can specify dtype in various contexts, such as when creating a new object using a constructor or when reading from a CSV file.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.astype.html
pandas.DataFrame.astype — pandas 3.0.3 documentation
{col: dtype, …}, where col is a column label and dtype is a numpy.dtype or Python type to cast one or more of the DataFrame’s columns to column-specific types. ... This keyword is now ignored; changing its value will have no impact on the method. Deprecated since version 3.0.0: This keyword is ignored and will be removed in pandas 4.0. Since pandas 3.0, this method always returns a new object using a lazy copy mechanism that defers copies until necessary (Copy-on-Write).
🌐
TutorialsPoint
tutorialspoint.com › how-do-stringdtype-objects-differ-from-object-dtype-in-python-pandas
How do StringDtype objects differ from object dtype in Python Pandas?
We can clearly see that the dtype of ds Series is an object, but if you try to get the type of a 2nd element it returns the output as an integer, not an object or a string. So it concludes, the dtype object doesn’t store only text data, it is a mixture of all data. Here define pd.StringDtype() explicitly to the dtype parameter of the pandas series method.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.dtype.html
pandas.Series.dtype — pandas 3.0.3 documentation - PyData |
Return the dtype object of the underlying data. ... Cast a pandas object to a specified dtype dtype.
🌐
Towards Data Science
towardsdatascience.com › home › latest › pandas: work on your dtypes!
pandas: work on your dtypes! | Towards Data Science
January 29, 2025 - Either you specify the dtype, by explicitly telling pandas what dtype to use for each column/series ... CONS: you don’t know what happened unless you review each dtype afterward, you might not have the most-appropriate dtype (like object because pandas did not figure what the column was about), ...
🌐
Towards Data Science
towardsdatascience.com › home › latest › why we need to use pandas new string dtype instead of object for textual data
Why We Need to Use Pandas New String Dtype Instead of Object for Textual Data | Towards Data Science
January 19, 2025 - One important thing to note here is that object datatype is still the default datatype for strings. To use StringDtype, we need to explicitly state it. We can pass "string" or pd.StringDtype() argument to dtype parameter to select string datatype.
🌐
Reddit
reddit.com › r/learnpython › is it possible to get a more specific dtype from pandas? decimal shows up as object, but will still throw errors specific to the decimal type.
r/learnpython on Reddit: Is it possible to get a more specific dtype from pandas? Decimal shows up as object, but will still throw errors specific to the Decimal type.
January 17, 2023 -

For some reason, some of the columns are being loaded as a Decimal rather than as a float - not my team, apparently can't be changed.

Is there a way to identify which columns are Decimal? df[col].dtype just returns "O" which makes it impossible to distinguish from objects using this method.