我正在使用 iloc 對我的資料框進行切片,如下所示:
df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
new_df = df.iloc[1:]
它作業正常,但 VsCode 中的 pylance 抱怨說:
Argument of type "slice" cannot be assigned to parameter "idx" of type "int | Tuple[IndexType | MaskType, IndexType | MaskType | int]" in function "__getitem__"
Type "slice" cannot be assigned to type "int | Tuple[IndexType | MaskType, IndexType | MaskType | int]"
"slice" is incompatible with "int"
"slice" is incompatible with "Tuple[IndexType | MaskType, IndexType | MaskType | int]"
知道為什么,這是什么意思嗎?
uj5u.com熱心網友回復:
我是這樣讀的:“你放了括號,所以我叫 get_item,里面應該是一個索引(idx),這個索引應該是型別:int | Tuple[IndexType | MaskType, IndexType | MaskType | int] 但是,切片與任何一個都不兼容。”
你試過用 替換:嗎, ?它說他期望一個 int 元組,也許這有幫助?
但你說它有效嗎?所以這可能是pylance的問題,不是嗎?
== 編輯 ==
答案是 : df.iloc[1:,:]
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/415726.html
標籤:
下一篇:根據另一個列條件過濾列值
