ZetCode

Pandas Data Types

last modified November 17, 2026 Python 3.15

A dtype, short for data type, describes what kind of value each entry in a column holds and how that value is stored in memory. An integer column behaves differently from a text column: you can add numbers but not names, and Pandas uses the dtype to decide which operations are allowed.

This article uses pandas 3.1.1. In pandas 3.x text columns use the str dtype by default; older versions used object instead, so you may see object in older tutorials and in output produced by earlier releases. The outputs shown here were verified with pandas 3.1.1.

Common dtypes

A Series is a one-dimensional column of data, and its dtype attribute reports the type of its values. The most common dtypes are int64 for whole numbers, float64 for numbers with a decimal part, bool for true/false values, str for text, and datetime64 for dates and times.

common_dtypes.py
import pandas as pd

s_int = pd.Series([1, 2, 3])
s_float = pd.Series([1.5, 2.5])
s_bool = pd.Series([True, False])
s_str = pd.Series(['a', 'b'])
s_dt = pd.to_datetime(pd.Series(['2026-01-01', '2026-01-02']))
print(s_int.dtype)
print(s_float.dtype)
print(s_bool.dtype)
print(s_str.dtype)
print(s_dt.dtype)

The five printed lines are int64, float64, bool, str and datetime64[us]. The suffix on the date dtype records the precision — here microseconds, written us. The text column is str because of the pandas 3.x default noted in the introduction.

$ python common_dtypes.py
int64
float64
bool
str
datetime64[us]

Inspecting dtypes with dtypes and info

On a DataFrame, dtypes lists the dtype of every column. The info() method prints a longer report: the number of rows, each column's name, dtype and count of non-null values, the dtype totals and the memory used. It is the quickest way to get an overview of a table you have just loaded.

inspecting_dtypes.py
import pandas as pd

df = pd.DataFrame({
    'id': [1, 2],
    'price': [1.5, 2.5],
    'active': [True, False],
    'city': ['London', 'Paris']
})
print(df.dtypes)
print()
df.info()

The dtypes output shows four different types. The info() report confirms that each column has two non-null values, lists the dtypes again at the bottom, and ends with the memory usage. The angle-bracketed line near the top is the class of the object, pandas.DataFrame.

$ python inspecting_dtypes.py
id          int64
price     float64
active       bool
city          str
dtype: object

<class 'pandas.DataFrame'>
RangeIndex: 2 entries, 0 to 1
Data columns (total 4 columns):
 #   Column  Non-Null Count  Dtype  
---  ------  --------------  -----  
 0   id      2 non-null      int64  
 1   price   2 non-null      float64
 2   active  2 non-null      bool   
 3   city    2 non-null      str    
dtypes: bool(1), float64(1), int64(1), str(1)
memory usage: 182.0 bytes

Converting with astype

astype converts a column or a whole DataFrame to a requested dtype. Passing a dictionary limits the conversion to the named columns, with each key mapped to its target dtype. Use it when you know the values are compatible — for instance, strings that are really numbers.

astype.py
import pandas as pd

df = pd.DataFrame({'a': ['1', '2', '3'], 'b': [1, 2, 3]})
converted = df.astype({'a': 'int64', 'b': 'float64'})
print(converted.dtypes)
print()
print(converted)

Column a holds the strings '1', '2' and '3', which become int64 numbers. Column b becomes float64, so its integers print as 1.0, 2.0 and 3.0. The dictionary has one entry per converted column.

$ python astype.py
a      int64
b    float64
dtype: object

   a    b
0  1  1.0
1  2  2.0
2  3  3.0

Converting with convert_dtypes

convert_dtypes chooses better dtypes automatically instead of being told which ones to use. In particular it moves columns to Pandas' nullable dtypes, which can store a missing value without forcing the column into float64. It is a convenient clean-up step after reading data from a file.

convert_dtypes.py
import pandas as pd

df = pd.DataFrame({
    'a': [1, 2, 3],
    'b': [True, False, True],
    'c': ['x', 'y', 'z']
})
print("before:")
print(df.dtypes)
converted = df.convert_dtypes()
print()
print("after convert_dtypes():")
print(converted.dtypes)

The original frame uses the default dtypes int64, bool and str. After conversion they become Int64, boolean and string — the nullable versions discussed in the next section. Notice that the names differ only in capitalisation, which is easy to miss.

$ python convert_dtypes.py
before:
a    int64
b     bool
c      str
dtype: object

after convert_dtypes():
a      Int64
b    boolean
c     string
dtype: object

Nullable dtypes

A nullable dtype can hold ordinary values and a missing value at the same time. NumPy-based dtypes such as int64 cannot represent missing integers, so a missing value forces them to become floating point. Pandas' own Int64, boolean and string dtypes solve this by using the special marker <NA> for missing entries.

nullable_dtypes.py
import pandas as pd

s = pd.Series([1, None, 3], dtype='Int64')
print(s)
print(s.dtype)
print()
b = pd.Series([True, None, False], dtype='boolean')
print(b)
print(b.dtype)
print()
t = pd.Series(['a', None, 'c'], dtype='string')
print(t)
print(t.dtype)

Each Series here contains one missing entry, printed as <NA>, and the surrounding integers, booleans and strings stay their proper type. Compare the dtype lines Int64, boolean and string with the lowercase NumPy forms from the previous section.

$ python nullable_dtypes.py
0       1
1    <NA>
2       3
dtype: Int64
Int64

0     True
1     <NA>
2    False
dtype: boolean
boolean

0       a
1    <NA>
2       c
dtype: string
string

Recovering types with infer_objects

Sometimes a column ends up with the generic object dtype even though all its values are of one kind — this often happens after mixing in a missing value or reading loosely typed data. infer_objects looks at the actual values and converts the column to a more specific dtype where it can.

infer_objects.py
import pandas as pd

df = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})
df['a'] = df['a'].astype('object')
print("before:")
print(df.dtypes)
result = df.infer_objects()
print()
print("after infer_objects():")
print(result.dtypes)

Column a was deliberately forced to object, so it appears that way in the first report. After infer_objects it is int64 again. Column b is already int64 and is left unchanged.

$ python infer_objects.py
before:
a    object
b     int64
dtype: object

after infer_objects():
a    int64
b    int64
dtype: object

Selecting columns by dtype

select_dtypes returns only the columns whose dtype matches a rule. The include argument names the types to keep: the string 'number' is a group covering both integers and floats, while 'bool' selects boolean columns. There is also an exclude argument for the opposite choice.

select_dtypes.py
import pandas as pd

df = pd.DataFrame({
    'id': [1, 2],
    'price': [1.5, 2.5],
    'active': [True, False],
    'city': ['London', 'Paris']
})
print("numeric only:")
print(df.select_dtypes(include='number'))
print()
print("bool only:")
print(df.select_dtypes(include='bool'))

The first result contains just id and price, the two numeric columns. The second contains only active. The city column is str in pandas 3.x and is excluded from both selections.

$ python select_dtypes.py
numeric only:
   id  price
0   1    1.5
1   2    2.5

bool only:
   active
0    True
1   False

Source

Pandas Basics: dtypes, Pandas DataFrame.astype Documentation, Pandas DataFrame.convert_dtypes Documentation, Pandas nullable integer data, and Pandas DataFrame.select_dtypes Documentation

In this article we have met the common Pandas dtypes, inspected them with dtypes and info(), changed them with astype and convert_dtypes, used nullable Int64, boolean and string, recovered specific types with infer_objects, and picked columns with select_dtypes. For working with text values see Pandas string methods, and for loading data with sensible types see reading CSV files.

Author

I am Jan Bodnar, a programmer and technical writer. I have been writing programming tutorials at ZetCode since 2007 and have published eight e-books. See about the author.

List all Pandas tutorials.