Issue
I am using iloc to slice my dataframe as below:
df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
new_df = df.iloc[1:]
It is working fine but pylance in VsCode is complaining that:
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]"
Any idea why and what does it mean?
Solution
I read it like this : "you put brackets so i call get_item, and inside should be an index (idx), and this index should be of type : int | Tuple[IndexType | MaskType, IndexType | MaskType | int] however, slice is compatible with none of it."
Have you tried replacing :
with ,
? it says he expect a Tuple of int, maybe that helps?
But you say it works? so it may be an issue with pylance, no?
== Edit ==
The answer is : df.iloc[1:,:]
Answered By - vinalti
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.