बेतरतीब (random) कॉलम चुनना
पिछले अभ्यास में, हमने pandas DataFrame से बेतरतीब पंक्तियाँ चुनने के दो तरीके देखे थे। हम वही फ़ंक्शन pandas DataFrame में कॉलम बेतरतीब चुनने के लिए भी इस्तेमाल कर सकते हैं.
Poker डेटासेट में से बेतरतीब 4 कॉलम चुनने के लिए, आप ये दो फ़ंक्शन इस्तेमाल करेंगे:
- बिल्ट-इन
pandasफ़ंक्शन.sample() NumPyका रैंडम इंटीजर नंबर जनरेटरnp.random.randint()
यह अभ्यास पाठ्यक्रम का हिस्सा है
pandas के साथ कुशल कोड लिखना
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Extract number of columns in dataset
D=poker_hands.shape[1]
# Select and time the selection of 4 of the dataset's columns using NumPy
np_start_time = time.time()
poker_hands.iloc[:,np.random.randint(____=____, ____=____, ____=____)]
print("Time using NymPy's random.randint(): {} sec".format(time.time() - np_start_time))