為什么這會引發錯誤?
我應該輸入什么真正的代碼?
我想按 2 列過濾資料框,然后從該子集中選擇一個隨機行。
代碼:
print(df_concepts.columns)
print(df_concepts[['id']['concept_code']].sample())
追溯:
Index(['id', 'vocabulary_id', 'concept_code', 'concept_text'], dtype='object')
print(df_concepts[['id']['concept_code']].sample())
TypeError: list indices must be integers or slices, not str
對不起,如果它很明顯
uj5u.com熱心網友回復:
首先更改嵌套串列,然后指定行數:
print(df_concepts[['id', 'concept_code']].sample(1))
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/465613.html
上一篇:元組串列串列,按元素求和
