In [1]:
# Viewing Data Types of All Columns
import pandas as pd
df = pd.DataFrame({
''''A'''': [1, 2, 3],
''''B'''': [''''x'''', ''''y'''', ''''z''''],
''''C'''': [1.1, 2.2, 3.3]
})
print(df.dtypes)
A int64 B object C float64 dtype: object
In [2]:
# Viewing Data Type of a Specific Column
import pandas as pd
df = pd.DataFrame({
''''A'''': [1, 2, 3],
''''B'''': [''''x'''', ''''y'''', ''''z''''],
''''C'''': [1.1, 2.2, 3.3]
})
print(df[''''A''''].dtype)
int64
In [3]:
# Viewing Data Types of Columns with Specific Data Types
import pandas as pd
df = pd.DataFrame({
''''A'''': [1, 2, 3],
''''B'''': [''''x'''', ''''y'''', ''''z''''],
''''C'''': [1.1, 2.2, 3.3]
})
int_columns = df.select_dtypes(include=''''int'''')
print(int_columns)
float_columns = df.select_dtypes(include=''''float'''')
print(float_columns)
A
0 1
1 2
2 3
C
0 1.1
1 2.2
2 3.3