dtype (Pandas)

A dtype is the data type pandas assigns to each column or Series, such as int64, float64, bool, datetime64, or str. It determines what operations are valid and how much memory the data uses.

Pandas

Each Series has one dtype, and a DataFrame can have a different dtype for each column. Inference depends on the values and Pandas version: text commonly inferred as object in Pandas 2, while Pandas 3 introduced a default str dtype. Explicit dtypes make examples and data contracts clearer.

An object dtype is a container for Python objects, so its entries can have different Python types. A nullable dtype such as Int64 or boolean has a defined missing-value representation; it is not the same dtype as NumPy int64 or bool.

Use df.dtypes or s.dtype to inspect storage, and astype to request a conversion. Check ranges and conversion errors before narrowing numeric types. A smaller dtype or categorical representation can save memory for suitable data, but measure the actual workload instead of assuming every conversion is beneficial.

Syntax

df.dtypes  |  s.astype('float64')

Examples

Python

import pandas as pd
mixed = pd.Series([1, "text"], dtype="object")
nullable = pd.Series([1, None], dtype="Int64")
print(mixed.dtype)
print([type(value).__name__ for value in mixed])
print(nullable.dtype)
print(nullable.isna().tolist())

Output:

object
['int', 'str']
Int64
[False, True]

Learn it in a lesson

See also

Back to the Dictionary