Python 无法理解iloc反转所有行与反转所有列的语法

Python 无法理解iloc反转所有行与反转所有列的语法,python,pandas,dataframe,Python,Pandas,Dataframe,我无法理解用于反转Pandas中所有行与所有列的语法 1. Reversing all rows : df.iloc[::-1] 2. Reversing all columns : df.iloc[:,::-1] 另一个相关的注意事项是,如何反转行和列 另一个相关的注意事项是,如何反转行和列 我认为解释切片最好是检查它是如何工作的,这里使用完全相同的原理: a[::-1] # all items in the array, reversed a[1::-1] # the first

我无法理解用于反转Pandas中所有行与所有列的语法

1. Reversing all rows : df.iloc[::-1]
2. Reversing all columns : df.iloc[:,::-1]
另一个相关的注意事项是,如何反转行和列

另一个相关的注意事项是,如何反转行和列

我认为解释切片最好是检查它是如何工作的,这里使用完全相同的原理:

a[::-1]    # all items in the array, reversed
a[1::-1]   # the first two items, reversed
a[:-3:-1]  # the last two items, reversed
a[-3::-1]  # everything except the last two items, reversed
熊猫行

df.iloc[::-1]    # all items in the array, reversed
df.iloc[1::-1]   # the first two items, reversed
df.iloc[:-3:-1]  # the last two items, reversed
df.iloc[-3::-1]  # everything except the last two items, reversed
顺便说一句,它与切片行相同,使用
获取所有列,但显然被忽略,因为工作方式相同:

df.iloc[::-1]
df.iloc[::-1, :]
....
熊猫列-首先
表示获取所有行,然后切片列

df.iloc[:, ::-1]    # all items in the array, reversed
df.iloc[:, 1::-1]   # the first two items, reversed
df.iloc[:, :-3:-1]  # the last two items, reversed
df.iloc[:, -3::-1]  # everything except the last two items, reversed

嘿,很好用。你能给我解释一下格式吗。我的理解很简单:意味着从头到尾选择一切。如果我们还想指定跳过级别(在本例中为-1),我们会添加另一个冒号,是吗?
df.iloc[:, ::-1]    # all items in the array, reversed
df.iloc[:, 1::-1]   # the first two items, reversed
df.iloc[:, :-3:-1]  # the last two items, reversed
df.iloc[:, -3::-1]  # everything except the last two items, reversed