我无法理解用于逆转Pandas中所有行和所有列的语法。
1. Reversing all rows : df.iloc[::-1]
2. Reversing all columns : df.iloc[:,::-1]在一个相关的注意事项上,将如何同时逆转行和列?
发布于 2020-04-04 10:46:49
在一个相关的说明中,将如何同时逆转行和列?
df.iloc[::-1, ::-1]我认为为了解释切片是最好的检查如何在lists中工作,这里使用完全相同的原则:
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, reversedPandas行
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, :]
....Pandas列-首先:意味着获取所有行,然后切片列
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, reversedhttps://stackoverflow.com/questions/61026839
复制相似问题