Since 0.17, you have to use the explicit conversions:

pd.to_datetime, pd.to_timedelta and pd.to_numeric

(As mentioned below, no more "magic", convert_objects has been deprecated in 0.17)

df = pd.DataFrame({'x': {0: 'a', 1: 'b'}, 'y': {0: '1', 1: '2'}, 'z': {0: '2018-05-01', 1: '2018-05-02'}})

df.dtypes

x    object
y    object
z    object
dtype: object

df

   x  y           z
0  a  1  2018-05-01
1  b  2  2018-05-02

You can apply these to each column you want to convert:

df["y"] = pd.to_numeric(df["y"])
df["z"] = pd.to_datetime(df["z"])    
df

   x  y          z
0  a  1 2018-05-01
1  b  2 2018-05-02

df.dtypes

x            object
y             int64
z    datetime64[ns]
dtype: object

and confirm the dtype is updated.


OLD/DEPRECATED ANSWER for pandas 0.12 - 0.16: You can use convert_objects to infer better dtypes:

In [21]: df
Out[21]: 
   x  y
0  a  1
1  b  2

In [22]: df.dtypes
Out[22]: 
x    object
y    object
dtype: object

In [23]: df.convert_objects(convert_numeric=True)
Out[23]: 
   x  y
0  a  1
1  b  2

In [24]: df.convert_objects(convert_numeric=True).dtypes
Out[24]: 
x    object
y     int64
dtype: object

Magic! (Sad to see it deprecated.)

Answer from Andy Hayden on Stack Overflow
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.dtypes.html
pandas.DataFrame.dtypes — pandas 3.0.6 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
🌐
Towards Data Science
towardsdatascience.com › home › latest › pandas: work on your dtypes!
pandas: work on your dtypes! | Towards Data Science
January 29, 2025 - Interpretation: anyone else (human or computer) will make assumptions on your data based on its dtype: if a column full of integers is stored as a string, they will treat it as strings, not integers · It enforces you to have clean data, like dealing with missing values or mis-recorded values. This will ease the data-crunching down the road a lot · And there are probably many more reasons, can you name a few? If so please write it in a comment. In this first post of my pandas series, I want to review the basics of pandas datatypes - or dtypes.
Discussions

python - Assign pandas dataframe column dtypes - Stack Overflow
I want to set the dtypes of multiple columns in pd.Dataframe (I have a file that I've had to manually parse into a list of lists, as the file was not amenable for pd.read_csv) import pandas as pd ... More on stackoverflow.com
🌐 stackoverflow.com
python - what are all the dtypes that pandas recognizes? - Stack Overflow
For pandas, would anyone know, if any datatype apart from (i) float64, int64 (and other variants of np.number like float32, int8 etc.) (ii) bool (iii) datetime64, timedelta64 such as string c... More on stackoverflow.com
🌐 stackoverflow.com
How do you guys handle pandas and its sh*tty data type inference
I feel like y'all need to learn how to read docs, you can (and should) specify your schema beforehand, which you can do by setting dtype param on read_csv to a dictionary in the form of "column_name": pandas_type. Docs More on reddit.com
🌐 r/Python
105
55
April 14, 2023
python - How to set dtypes by column in pandas DataFrame - Stack Overflow
I want to bring some data into a pandas DataFrame and I want to assign dtypes for each column on import. I want to be able to do this for larger datasets with many different columns, but, as an ex... More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 8
102

Since 0.17, you have to use the explicit conversions:

pd.to_datetime, pd.to_timedelta and pd.to_numeric

(As mentioned below, no more "magic", convert_objects has been deprecated in 0.17)

df = pd.DataFrame({'x': {0: 'a', 1: 'b'}, 'y': {0: '1', 1: '2'}, 'z': {0: '2018-05-01', 1: '2018-05-02'}})

df.dtypes

x    object
y    object
z    object
dtype: object

df

   x  y           z
0  a  1  2018-05-01
1  b  2  2018-05-02

You can apply these to each column you want to convert:

df["y"] = pd.to_numeric(df["y"])
df["z"] = pd.to_datetime(df["z"])    
df

   x  y          z
0  a  1 2018-05-01
1  b  2 2018-05-02

df.dtypes

x            object
y             int64
z    datetime64[ns]
dtype: object

and confirm the dtype is updated.


OLD/DEPRECATED ANSWER for pandas 0.12 - 0.16: You can use convert_objects to infer better dtypes:

In [21]: df
Out[21]: 
   x  y
0  a  1
1  b  2

In [22]: df.dtypes
Out[22]: 
x    object
y    object
dtype: object

In [23]: df.convert_objects(convert_numeric=True)
Out[23]: 
   x  y
0  a  1
1  b  2

In [24]: df.convert_objects(convert_numeric=True).dtypes
Out[24]: 
x    object
y     int64
dtype: object

Magic! (Sad to see it deprecated.)

2 of 8
85

you can set the types explicitly with pandas DataFrame.astype(dtype, copy=True, raise_on_error=True, **kwargs) and pass in a dictionary with the dtypes you want to dtype

here's an example:

import pandas as pd
wheel_number = 5
car_name = 'jeep'
minutes_spent = 4.5

# set the columns
data_columns = ['wheel_number', 'car_name', 'minutes_spent']

# create an empty dataframe
data_df = pd.DataFrame(columns = data_columns)
df_temp = pd.DataFrame([[wheel_number, car_name, minutes_spent]],columns = data_columns)
data_df = data_df.append(df_temp, ignore_index=True) 

you get

In [11]: data_df.dtypes
Out[11]:
wheel_number     float64
car_name          object
minutes_spent    float64
dtype: object

with

data_df = data_df.astype(dtype= {"wheel_number":"int64",
        "car_name":"object","minutes_spent":"float64"})

now you can see that it's changed

In [18]: data_df.dtypes
Out[18]:
wheel_number       int64
car_name          object
minutes_spent    float64
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › pandas-dataframe-dtypes
Pandas DataFrame dtypes Property | Find Data Type of Columns - GeeksforGeeks
July 11, 2025 - Pandas DataFrame.dtypes attribute returns a series with the data type of each column.
🌐
W3Schools
w3schools.com › python › pandas › ref_df_dtypes.asp
Pandas DataFrame dtypes Property
Pandas HOME Pandas Intro Pandas ... Cleaning Wrong Data Removing Duplicates ... The dtypes property returns data type of each column in the DataFrame....
Find elsewhere
Top answer
1 of 3
71

pandas borrows its dtypes from numpy. For demonstration of this see the following:

import pandas as pd

df = pd.DataFrame({'A': [1,'C',2.]})
df['A'].dtype

>>> dtype('O')

type(df['A'].dtype)

>>> numpy.dtype

You can find the list of valid numpy.dtypes in the documentation:

'?' boolean

'b' (signed) byte

'B' unsigned byte

'i' (signed) integer

'u' unsigned integer

'f' floating-point

'c' complex-floating point

'm' timedelta

'M' datetime

'O' (Python) objects

'S', 'a' zero-terminated bytes (not recommended)

'U' Unicode string

'V' raw data (void)

pandas should support these types. Using the astype method of a pandas.Series object with any of the above options as the input argument will result in pandas trying to convert the Series to that type (or at the very least falling back to object type); 'u' is the only one that I see pandas not understanding at all:

df['A'].astype('u')

>>> TypeError: data type "u" not understood

This is a numpy error that results because the 'u' needs to be followed by a number specifying the number of bytes per item in (which needs to be valid):

import numpy as np

np.dtype('u')

>>> TypeError: data type "u" not understood

np.dtype('u1')

>>> dtype('uint8')

np.dtype('u2')

>>> dtype('uint16')

np.dtype('u4')

>>> dtype('uint32')

np.dtype('u8')

>>> dtype('uint64')

# testing another invalid argument
np.dtype('u3')

>>> TypeError: data type "u3" not understood

To summarise, the astype methods of pandas objects will try and do something sensible with any argument that is valid for numpy.dtype. Note that numpy.dtype('f') is the same as numpy.dtype('float32') and numpy.dtype('f8') is the same as numpy.dtype('float64') etc. Same goes for passing the arguments to pandas astype methods.

To locate the respective data type classes in NumPy, the Pandas docs recommends this:

def subdtypes(dtype):
    subs = dtype.__subclasses__()
    if not subs:
        return dtype
    return [dtype, [subdtypes(dt) for dt in subs]]

subdtypes(np.generic)

Output:

[numpy.generic,
 [[numpy.number,
   [[numpy.integer,
     [[numpy.signedinteger,
       [numpy.int8,
        numpy.int16,
        numpy.int32,
        numpy.int64,
        numpy.int64,
        numpy.timedelta64]],
      [numpy.unsignedinteger,
       [numpy.uint8,
        numpy.uint16,
        numpy.uint32,
        numpy.uint64,
        numpy.uint64]]]],
    [numpy.inexact,
     [[numpy.floating,
       [numpy.float16, numpy.float32, numpy.float64, numpy.float128]],
      [numpy.complexfloating,
       [numpy.complex64, numpy.complex128, numpy.complex256]]]]]],
  [numpy.flexible,
   [[numpy.character, [numpy.bytes_, numpy.str_]],
    [numpy.void, [numpy.record]]]],
  numpy.bool_,
  numpy.datetime64,
  numpy.object_]]

Pandas accepts these classes as valid types. For example, dtype={'A': np.float}.

NumPy docs contain more details and a chart:

2 of 3
59

EDIT Feb 2020 following pandas 1.0.0 release

Pandas mostly uses NumPy arrays and dtypes for each Series (a dataframe is a collection of Series, each which can have its own dtype). NumPy's documentation further explains dtype, data types, and data type objects. In addition, the answer provided by @lcameron05 provides an excellent description of the numpy dtypes. Furthermore, the pandas docs on dtypes have a lot of additional information.

The main types stored in pandas objects are float, int, bool, datetime64[ns], timedelta[ns], and object. In addition these dtypes have item sizes, e.g. int64 and int32.

By default integer types are int64 and float types are float64, REGARDLESS of platform (32-bit or 64-bit). The following will all result in int64 dtypes.

Numpy, however will choose platform-dependent types when creating arrays. The following WILL result in int32 on 32-bit platform. One of the major changes to version 1.0.0 of pandas is the introduction of pd.NA to represent scalar missing values (rather than the previous values of np.nan, pd.NaT or None, depending on usage).

Pandas extends NumPy's type system and also allows users to write their on extension types. The following lists all of pandas extension types.

1) Time zone handling

Kind of data: tz-aware datetime (note that NumPy does not support timezone-aware datetimes).

Data type: DatetimeTZDtype

Scalar: Timestamp

Array: arrays.DatetimeArray

String Aliases: 'datetime64[ns, ]'

2) Categorical data

Kind of data: Categorical

Data type: CategoricalDtype

Scalar: (none)

Array: Categorical

String Aliases: 'category'

3) Time span representation

Kind of data: period (time spans)

Data type: PeriodDtype

Scalar: Period

Array: arrays.PeriodArray

String Aliases: 'period[]', 'Period[]'

4) Sparse data structures

Kind of data: sparse

Data type: SparseDtype

Scalar: (none)

Array: arrays.SparseArray

String Aliases: 'Sparse', 'Sparse[int]', 'Sparse[float]'

5) IntervalIndex

Kind of data: intervals

Data type: IntervalDtype

Scalar: Interval

Array: arrays.IntervalArray

String Aliases: 'interval', 'Interval', 'Interval[<numpy_dtype>]', 'Interval[datetime64[ns, ]]', 'Interval[timedelta64[]]'

6) Nullable integer data type

Kind of data: nullable integer

Data type: Int64Dtype, ...

Scalar: (none)

Array: arrays.IntegerArray

String Aliases: 'Int8', 'Int16', 'Int32', 'Int64', 'UInt8', 'UInt16', 'UInt32', 'UInt64'

7) Working with text data

Kind of data: Strings

Data type: StringDtype

Scalar: str

Array: arrays.StringArray

String Aliases: 'string'

8) Boolean data with missing values

Kind of data: Boolean (with NA)

Data type: BooleanDtype

Scalar: bool

Array: arrays.BooleanArray

String Aliases: 'boolean'

🌐
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.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.select_dtypes.html
pandas.DataFrame.select_dtypes — pandas 3.0.6 documentation
See the numpy dtype hierarchy · To select datetimes, use np.datetime64, 'datetime' or 'datetime64' To select timedeltas, use np.timedelta64, 'timedelta' or 'timedelta64' To select Pandas categorical dtypes, use 'category' To select Pandas datetimetz dtypes, use 'datetimetz' or 'datetime64[ns, tz]' Examples ·
🌐
Dsc80
notes.dsc80.com › content › 02 › data-types.html
Pandas Data Types and Performance Considerations — Data Science in Practice
In Pandas, a Data Type is a classification that specifies the type of the values of a column. Understanding data types in Pandas leads to cleaner, better optimized (in both space and time), less error-prone code.
🌐
Pandas
pandas.pydata.org › docs › reference › arrays.html
pandas arrays, scalars, and data types — pandas 3.0.6 documentation
Timestamp, a subclass of datetime.datetime, is pandas’ scalar type for timezone-naive or timezone-aware datetime data. NaT is the missing value for datetime data. A collection of timestamps may be stored in a arrays.DatetimeArray. For timezone-aware data, the .dtype of a arrays.DatetimeArray is a DatetimeTZDtype.
🌐
APXML
apxml.com › courses › intro-eda-course › chapter-2-data-loading-inspection-cleaning › understanding-data-types
Pandas Data Types (dtypes) Explained
After loading your data and getting a first glimpse using methods like .head(), .tail(), and .shape(), the next logical step is to understand the kind of data stored in each column. In Pandas, this information is captured by the data type, or dtype, associated with each Series (column) in your DataFrame.
🌐
Medium
datascientyst.medium.com › everything-you-should-know-about-dtype-in-pandas-1084e7dbe7b6
Everything You Should Know About Dtype in Pandas | by DataScientyst | Medium
September 1, 2021 - How to read and convert Kaggle data to Pandas DataFrame: How to Search and Download Kaggle Dataset to Pandas DataFrame · To get dtypes details for the whole DataFrame you can use attribute — dtypes:
🌐
Cbseacademic
cbseacademic.nic.in › web_material › SQP › ClassXII_2024_25 › InformaticsPractices-SQP.pdf pdf
Page 1 of 14 SAMPLE QUESTION PAPER (THEORY) CLASS XII SESSION: 2024-25
import Pandas as pd · D1 = {'Name': 'Rakshit', 'Age': 25} D2 = {'Name': 'Paul', 'Age': 30} D3 = {'Name': 'Ayesha", 'Age': 28} data = [D1,D2,D3) df = pd.Dataframe(data) print(df) OR · Complete the given Python code to get the required output (ignore the dtype ·
🌐
Medium
medium.com › @amit25173 › understanding-pandas-dataframe-dtypes-0a2f75eb8a38
Understanding pandas.DataFrame.dtypes | by Amit Yadav | Medium
March 6, 2025 - In simple terms, dtypes tells you the data type of each column in your DataFrame. It’s like flipping over a product to read its label—you immediately see what’s inside. ... import pandas as pd data = { 'Name': ['Alice', 'Bob', 'Charlie'], ...
🌐
PyPI
pypi.org › project › transformers
transformers · PyPI
import torch from transformers import pipeline chat = [ {"role": "system", "content": "You are a sassy, wise-cracking robot as imagined by Hollywood circa 1986."}, {"role": "user", "content": "Hey, can you tell me any fun things to do in New York?"} ] pipeline = pipeline(task="text-generation", model="meta-llama/Meta-Llama-3-8B-Instruct", dtype=torch.bfloat16, device_map="auto") response = pipeline(chat, max_new_tokens=512) print(response[0]["generated_text"][-1]["content"])
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › change-data-type-for-one-or-more-columns-in-pandas-dataframe
Change Data Type for one or more columns in Pandas Dataframe - GeeksforGeeks
July 11, 2025 - convert_dtypes() method in Pandas automatically converts columns to the most appropriate data type based on the values present.