w3resource

Python Scikit learn: Get the number of observations, missing values and nan values

Python Machine learning Iris Basic: Exercise-3 with Solution

Write a Python program to get the number of observations, missing values and nan values.

Sample Solution:

Python Code:

import pandas as pd
iris = pd.read_csv("iris.csv")
print(iris.info())

Output:


RangeIndex: 150 entries, 0 to 149
Data columns (total 6 columns):
Id               150 non-null int64
SepalLengthCm    150 non-null float64
SepalWidthCm     150 non-null float64
PetalLengthCm    150 non-null float64
PetalWidthCm     150 non-null float64
Species          150 non-null object
dtypes: float64(4), int64(1), object(1)
memory usage: 7.1+ KB
None

Python Code Editor:


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

Previous: Write a Python program using Scikit-learn to print the keys, number of rows-columns, feature names and the description of the Iris data.
Next: Write a Python program to create a 2-D array with ones on the diagonal and zeros elsewhere. Now convert the NumPy array to a SciPy sparse matrix in CSR format.

What is the difficulty level of this exercise?