w3resource

Python Scikit learn: Print the keys, number of rows-columns, feature names and the description of the Iris data

Python Machine learning Iris Basic: Exercise-2 with Solution

Write a Python program using Scikit-learn to print the keys, number of rows-columns, feature names and the description of the Iris data.

Sample Solution:

Python Code:

import pandas as pd
iris_data = pd.read_csv("iris.csv")
print("\nKeys of Iris dataset:")
print(iris_data.keys())
print("\nNumber of rows and columns of Iris dataset:")
print(iris_data.shape) 

Sample Output:

Keys of Iris dataset:
Index(['Id', 'SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm',
       'Species'],
      dtype='object')

Number of rows and columns of Iris dataset:
(150, 6)

Python Code Editor:


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to load the iris data from a given csv file into a dataframe and print the shape of the data, type of the data and first 3 rows.
Next: Write a Python program to get the number of observations, missing values and nan values.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/machine-learning/scikit-learn/iris/python-machine-learning-scikit-learn-iris-basic-exercise-2.php