We can use the pandas.DataFrame.dtypes property to print the data types of each attribute of a dataset. In this article, we will read from a CSV file and then, use the pandas.DataFrame.dtypes property to print the data types of each attribute of the dataset.
We can use the following Python code for that purpose:
import pandas
data = pandas.read_csv("iris.csv")
print(data.dtypes)
Here, we first import the pandas module and then, use the pandas.read_csv() function to read from a CSV file. The pandas.read_csv() function returns a DataFrame. We now use the pandas.DataFrame.dtypes property to print the data types of each attribute of the dataset.
The output of the above program will be like the following:
sepal_length float64 sepal_width float64 petal_length float64 petal_width float64 species object dtype: object
Please note that “iris.csv” file contains various information such as petal length, petal width, sepal length, sepal width, and species of each flowers. So, the dataset contains five columns all total. From the above output, we can see that the first four columns contain floating point numbers. And the last column contains objects. Actually, the last column contains strings objects.








































0 Comments