import pandas as pd data = {} data['A'] = [1,2,3,4,5] data['B'] = ['A','B','C','D','E'] df = pd.DataFrame(data) print(df) # Check all column types print(df.dtypes) # Check data type of a certain column print(df.a.dtype)
visibility 34
comment 0
access_time 6 months ago
language English
codeCheck Column Data Types in a Pandas DataFrame
This code snippet provide examples of checking column data types in a DataFrame using dtype
and dtypes
.
Sample output:
>>> print(df.dtypes)
a int64
b object
dtype: object
>>> print(df.a.dtype)
int64
Code snippet
copyright
This page is subject to Site terms.
Log in with external accounts
comment Comments
No comments yet.
warning Please login first to view stats information.
code
PySpark DataFrame - Add or Subtract Milliseconds from Timestamp Column
article
Python: Read Data from SQLite via JDBC
article
Write and read parquet files in Python / Spark
article
Data Operations with SQLite Database via Python
code
Subscribe to Multiple Topics in Kafka Consumer
Read more (92)