Python Scikit learn: Print the shape of the data, type of the data and first 3 rows

Python Machine learning Iris Basic: Exercise-1 with Solution

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.

Sample Solution:

Python Code:

import pandas as pd
data = pd.read_csv("iris.csv")
print("Shape of the data:")
print("\nData Type:")
print("\nFirst 3 rows:")


Shape of the data:
(150, 6)

Data Type:

First 3 rows:
   Id  SepalLengthCm     ...       PetalWidthCm      Species
0   1            5.1     ...                0.2  Iris-setosa
1   2            4.9     ...                0.2  Iris-setosa
2   3            4.7     ...                0.2  Iris-setosa

[3 rows x 6 columns]

Python Code Editor:

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

Previous: Python Machine learning Iris Basic Exercises Home.
Next: Write a Python program using Scikit-learn to print the keys, number of rows-columns, feature names and the description of the Iris data.

What is the difficulty level of this exercise?