Schema inspection
Before cleaning or validation, inspect the table schema to find columns whose types need attention.
Pandas · Module
DataFrame.dtypes is a property that returns a Series describing the dtype of every column. The Series uses the DataFrame’s column labels as its index.
Accessing DataFrame.dtypes produces a Series that maps every column label to that column’s data type. The Series keeps the DataFrame’s column labels as its index, making it useful for inspecting schema before selecting, converting, or validating columns.
DataFrame.dtypespandas.Series — the data type of each column.
import pandas as pd
frame = pd.DataFrame({
"price": [1.5, 2.0],
"count": [1, 2],
"label": ["a", "b"],
})
print(frame.dtypes)Creates a heterogeneous DataFrame and prints the dtype associated with each column.
Before cleaning or validation, inspect the table schema to find columns whose types need attention.
Use the reported types to decide which columns need conversion or specialized processing.
Review mixed-type columns that may have been inferred as object.
DataFrame.dtypes is a property, so it is accessed without parentheses. It returns a pandas Series whose values are the dtypes of the DataFrame’s columns and whose index is the original column index.
Follow-up: How would you use the result to select columns by type? Use DataFrame.select_dtypes, which filters columns according to include and exclude dtype criteria.
Each output Series entry corresponds to one DataFrame column. The Series index contains the DataFrame’s original column labels, while its values describe the respective column types.
Follow-up: What happens when a column contains mixed types? The documentation says such columns are stored with the object dtype.
It is useful for examining a heterogeneous table before type-dependent processing, such as identifying numeric, temporal, or object-typed columns. It reports the inferred or assigned dtype currently held by each column.
Follow-up: How can types be changed? DataFrame.astype casts a pandas object to a specified dtype, while DataFrame.convert_dtypes converts columns to suitable dtypes supporting pd.NA.
Series.dtypesDataFrame.select_dtypesDataFrame.astypeDataFrame.convert_dtypes