LoslegenKostenlos loslegen

.apply() function in every cell

As you saw in the lesson, you can use .apply() to map a function to every cell of the DataFrame, regardless the column or the row.

You're going to try it out on the poker_hands dataset. You will use .apply() to square every cell of the DataFrame. The native Python way to square a number n is n**2.

Diese Übung ist Teil des Kurses

Writing Efficient Code with pandas

Kurs anzeigen

Anleitung zur Übung

  • Define the lambda transformation for the square.
  • Apply the transformation using the .apply() function.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Define the lambda transformation
get_square = ____ x: ____

# Apply the transformation
data_sum = poker_hands.____(____)
print(data_sum.head())
Code bearbeiten und ausführen