我對 Python 資料框很陌生。
在以下情況下:
| ID | 姓名 | 結果 |
|---|---|---|
| 1 | 卡拉 | 一個 |
| 2 | 本 | 乙 |
| 3 | 伊維 | 一個 |
| 4 | 梅爾 | C |
我想回傳第一次出現結果 A (Cara) 的學生的姓名。然后我想對 A (Evie) 的第二次出現做同樣的事情并重復直到出現 5 次。我該怎么做?
uj5u.com熱心網友回復:
嘗試這個:
students=df.loc[df[result]=="A"].head(5)
print(student["name"].to_list())
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/518602.html
標籤:Python熊猫数据框
