MulaiMulai sekarang secara gratis

Vectorization methods for looping a DataFrame

Now that you're familiar with vectorization in pandas and NumPy, you're going to compare their respective performances yourself.

Your task is to calculate the variance of all the hands in each hand using the vectorization over pandas Series and then modify your code using the vectorization over Numpy ndarrays method.

Latihan ini adalah bagian dari kursus

Writing Efficient Code with pandas

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Calculate the variance in each hand
start_time = time.time()
poker_var = poker_hands[[____, ____, ____, ____, ____]].____(____=____)
print("Time using pandas vectorization: {} sec".format(time.time() - start_time))
print(poker_var.head())
Edit dan Jalankan Kode