Search⌘ K
AI Features

Solution: Data Manipulation and Indexing

Learn how to manipulate pandas Series by applying conditional logic to label data, replace missing numeric values with the median, and customize indexes using practical coding examples. This lesson helps you understand key techniques for effective data cleaning and organization in pandas.

Problem 1: Solution

Given a Series marks, create a Series from a numeric column of Series marks that has the value of high if it's equal to or above the mean and low if it's below the mean mean using np.select.

Python 3.10.4
import pandas as pd
import numpy as np
marks = pd.Series([13,45,20,46,0,90,12])
low_or_high = np.select([marks<marks.agg('mean'), marks>marks.agg('mean')], ['low', 'high'])
print(marks.tolist())
print (low_or_high)
...