Skip to content

Commit 0c04e97

Browse files
committed
Update frame.py
expanded example
1 parent 47e0b1b commit 0c04e97

File tree

1 file changed

+53
-4
lines changed

1 file changed

+53
-4
lines changed

pandas/core/frame.py

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5157,7 +5157,7 @@ def lookup(self, row_labels, col_labels) -> np.ndarray:
51575157
51585158
Examples
51595159
--------
5160-
>>> df = pd.DataFrame(
5160+
>>> grades = pd.DataFrame(
51615161
... {
51625162
... "Math_Sem1": [85, 92, 78, 88, 95],
51635163
... "Math_Sem2": [88, 90, 82, 85, 93],
@@ -5168,9 +5168,58 @@ def lookup(self, row_labels, col_labels) -> np.ndarray:
51685168
... },
51695169
... index=["Alice", "Bob", "Charlie", "David", "Eve"],
51705170
... )
5171-
>>> student_top = df.rank(1).idxmax(1) # Column name for student's top score
5172-
>>> df.lookup(df.index, student_top)
5173-
array([95, 92, 92, 90, 95])
5171+
>>> feedback = pd.DataFrame(
5172+
... {
5173+
... "Math_Sem1": [
5174+
... "Strong analytical skills",
5175+
... "Excellent problem-solving",
5176+
... "Needs more practice",
5177+
... "Solid understanding",
5178+
... "Exceptional reasoning",
5179+
... ],
5180+
... "Math_Sem2": [
5181+
... "Improved advanced techniques",
5182+
... "Consistent high performance",
5183+
... "Significant progress",
5184+
... "Steady improvement",
5185+
... "Consistently exceptional",
5186+
... ],
5187+
... "Science_Sem1": [
5188+
... "Excellent inquiry skills",
5189+
... "Good theoretical concepts",
5190+
... "Strong methodological interest",
5191+
... "Needs focus",
5192+
... "Outstanding curiosity",
5193+
... ],
5194+
... "Science_Sem2": [
5195+
... "Advanced scientific principles",
5196+
... "Improved practical skills",
5197+
... "Growing scientific reasoning",
5198+
... "Better lab engagement",
5199+
... "Continued excellence",
5200+
... ],
5201+
... "English_Sem1": [
5202+
... "Exceptional writing",
5203+
... "Strong language use",
5204+
... "Needs confident expression",
5205+
... "Solid literary analysis",
5206+
... "Creative insights",
5207+
... ],
5208+
... "English_Sem2": [
5209+
... "Refined writing techniques",
5210+
... "Improved expression",
5211+
... "More confident analysis",
5212+
... "Developing writing style",
5213+
... "Maintained high-level writing",
5214+
... ],
5215+
... },
5216+
... index=["Alice", "Bob", "Charlie", "David", "Eve"],
5217+
... )
5218+
>>> student_top = grades.rank(1).idxmax(1) # student's top score
5219+
>>> feedback.lookup(student_top.index, student_top)
5220+
array(['Exceptional writing', 'Excellent problem-solving',
5221+
'Strong methodological interest', 'Solid literary analysis',
5222+
'Exceptional reasoning'], dtype=object)
51745223
"""
51755224
n = len(row_labels)
51765225
if n != len(col_labels):

0 commit comments

Comments
 (0)