Aan de slagGa gratis aan de slag

.apply() for rows iteration

.apply() is a very useful to iterate through the rows of a DataFrame and apply a specific function.

You will work on a subset of the poker_hands dataset, which includes only the rank of all the five cards of each hand in each row (this subset is generated for you in the script). You're going to get the variance of every hand for all ranks, and every rank for all hands.

Deze oefening maakt deel uit van de cursus

Writing Efficient Code with pandas

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Define the lambda transformation
get_variance = ____

# Apply the transformation
data_tr = poker_hands[['R1', 'R2', 'R3', 'R4', 'R5']].____(____, ____)
print(data_tr.head())
Code bewerken en uitvoeren