How can you view the data types of each column in Python?
In Python, you can use the “dtypes” attribute in the pandas library to view the data types of each column. The specific steps are as follows:
- bears
import pandas as pd
- Create a DataFrame.
data = {'A': [1, 2, 3],
'B': [4.5, 5.6, 6.7],
'C': ['x', 'y', 'z']}
df = pd.DataFrame(data)
- data types
print(df.dtypes)
The output will display the data types of each column, such as:
A int64
B float64
C object
dtype: object
In the examples provided, column “A” is of data type int64, column “B” is of data type float64, and column “C” is of data type object (string).