Solution: Looping, Aggregation, and apply() Method
See the solution to the problems related to looping, aggregation, and the apply() method.
We'll cover the following...
Problem 1: Solution
Given the following dataset:
100 56 1712 23 149 3 6532 19 4199 100 41
Create a DataFrame named df
. Loop over each row and calculate the maximum and minimum values.
Press + to interact
import numpy as npimport pandas as pdmatrix = [(100, 56, 17),(12, 23, 1),(49, 3, 65),(32, 19, 43),(99, 100, 41)]# Create a DataFramedf = pd.DataFrame(matrix, index = list('abcde'), columns = list('xyz'))# iterate through each row and selectfor i in range(len(df)):print("max value in row", i,": ",max(df.iloc[i, 0], df.iloc[i,1], df.iloc[i, 2]))print("min value in row", i,": ",min(df.iloc[i, 0], df.iloc[i,1], df.iloc[i, 2]))
...