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.
import pandas as pd data = pd.read_csv("iris.csv") print("Shape of the data:") print(data.shape) print("\nData Type:") print(type(data)) print("\nFirst 3 rows:") print(data.head(3))
Shape of the data: (150, 6) Data Type: <class 'pandas.core.frame.DataFrame'> 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?
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework