Additional arguments
चलिए .apply() मेथड में अतिरिक्त आर्ग्युमेंट्स का उपयोग करते हैं!
आपका काम scores में दो नई कॉलम्स बनाना है:
mean: math score, reading score और writing score का row-wise mean मानrank:meanस्कोर कितना ऊँचा है, यह बताए:'high'यदि mean मान \(> 90\)'medium'यदि mean मान \(> 60\) लेकिन \(\leq\) 90'low'यदि mean मान \(\leq 60\)
इसे पूरा करने के लिए, आपको rank नाम का फंक्शन परिभाषित करना होगा, जो किसी series को लेकर दो मानों वाली एक list लौटाए: series का mean और ऊपर दिए नियम के अनुसार एक string.
मॉड्यूल numpy पहले से np नाम से इम्पोर्ट किया गया है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में कोडिंग इंटरव्यू प्रश्नों का अभ्यास
अभ्यास निर्देश
- इनपुट series का mean निकालें.
- mean और उसका rank एक list के रूप में लौटाएँ.
rank()के आउटपुट कोscoresकी नई कॉलम्स में डालें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
def rank(series):
# Calculate the mean of the input series
mean = ____
# Return the mean and its rank as a list
if ____:
return ____
if ____:
return ____
return ____
# Insert the output of rank() into new columns of scores
cols = ['math score', 'reading score', 'writing score']
scores[['mean', 'rank']] = scores[cols].____
print(scores[['mean', 'rank']].head())