0
0
Pandasdata~10 mins

dtypes for column data types in Pandas - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - dtypes for column data types
Create DataFrame
Access .dtypes
Return Series
Show each column's data type
Use for analysis or debugging
We create a DataFrame, then access its .dtypes attribute to get a Series showing each column's data type.
Execution Sample
Pandas
import pandas as pd

df = pd.DataFrame({
  'A': [1, 2],
  'B': [3.5, 4.5],
  'C': ['x', 'y']
})
print(df.dtypes)
This code creates a DataFrame with three columns and prints the data types of each column.
Execution Table
StepActionCode/ExpressionResult
1Create DataFramedf = pd.DataFrame({'A': [1, 2], 'B': [3.5, 4.5], 'C': ['x', 'y']})DataFrame with columns A, B, C
2Access dtypes attributedf.dtypesSeries showing: A int64, B float64, C object
3Print dtypesprint(df.dtypes)Output: A int64 B float64 C object dtype: object
💡 All columns' data types are shown as a Series; no further steps.
Variable Tracker
VariableStartAfter Step 1After Step 2Final
dfundefinedDataFrame with columns A, B, CSame DataFrameSame DataFrame
df.dtypesundefinedundefinedSeries with dtypesSeries with dtypes
Key Moments - 2 Insights
Why does the 'C' column show 'object' instead of 'string'?
In pandas, text columns are stored as 'object' dtype by default, which means they hold Python objects like strings. See execution_table step 2 where 'C' is 'object'.
Is df.dtypes a DataFrame or something else?
df.dtypes returns a pandas Series, not a DataFrame. It lists each column name as index and its data type as values, as shown in execution_table step 2.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the dtype of column 'B' after step 2?
Aobject
Bint64
Cfloat64
Dbool
💡 Hint
Check the 'Result' column in execution_table row for step 2.
At which step is the DataFrame 'df' created?
AStep 2
BStep 1
CStep 3
DNo step creates it
💡 Hint
Look at the 'Action' column in execution_table for when df is assigned.
If column 'A' had float numbers instead of integers, how would df.dtypes change?
AColumn 'A' dtype would be float64
BColumn 'A' dtype would be int64
CColumn 'A' dtype would be object
DNo change in dtypes
💡 Hint
Refer to variable_tracker and how dtypes reflect actual data types.
Concept Snapshot
Use df.dtypes to see each column's data type in a DataFrame.
It returns a Series with column names as index and dtypes as values.
Common dtypes: int64 for integers, float64 for decimals, object for text.
Useful for checking data before analysis or cleaning.
Full Transcript
We start by creating a pandas DataFrame with three columns: A with integers, B with floats, and C with strings. Then, we access the .dtypes attribute of the DataFrame, which returns a Series showing the data type of each column. The output shows that column A is int64, B is float64, and C is object (which pandas uses for text). This helps us understand what kind of data each column holds. The variable tracker shows how df and df.dtypes change during execution. Key moments clarify why text columns show as object and that df.dtypes returns a Series, not a DataFrame. The quiz tests understanding of dtypes and execution steps. Finally, the snapshot summarizes how to use df.dtypes to check column data types.