How to Check Data Type
Checking Data Types with dtype
dtypeimport pandas as pd
# Create a DataFrame
data = {
'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 35],
'City': ['New York', 'Los Angeles', 'Chicago']
}
df = pd.DataFrame(data)
# Check if a column is numeric
print(df['Age'].dtype)
# Check if a column is string (object type in Pandas)
print(df['Name'].dtype)Using pd.api.types for Type Checking
pd.api.types for Type CheckingUse Cases
Last updated