Python是進行數據分析的一種出色語言,主要是因為以數據為中心的python軟件包具有奇妙的生態係統。 Pandas是其中的一種,使導入和分析數據更加容易。
Pandas Index.argsort()
函數返回將對索引進行排序的整數索引。默認情況下,排序順序已設置為遞增順序。
用法: Index.argsort(*args, **kwargs)
參數:
*args:傳遞給numpy.ndarray.argsort
**kwargs:傳遞給numpy.ndarray.argsort
返回:numpy.ndarray
如果用作索引器,則將對索引進行排序的整數索引
範例1:采用Index.argsort()
函數查找將對給定索引進行排序的索引順序。
# importing pandas as pd
import pandas as pd
# Creating the Index
df = pd.Index([17, 69, 33, 5, 10, 74, 10, 5])
# Print the Index
df
輸出:
讓我們找到對索引進行排序的索引的順序。
# to find the ordering of indices
# that would sort the df Index
df.argsort()
輸出:
正如我們在輸出中看到的那樣,該函數已返回索引的順序,該順序將對給定的Index進行排序。我們可以通過基於順序打印索引來驗證這一點。
# Printing the Index based on the
# result of the argsort() function
df[df.argsort()]
輸出:
正如我們在輸出中看到的那樣,它是按排序順序打印的。
範例2:采用Index.argsort()
函數查找將對給定索引進行排序的索引順序。
# importing pandas as pd
import pandas as pd
# Creating the Index
df = pd.Index(['Sam', 'Alex', 'Olivia',
'Dan', 'Brook', 'Katherine'])
# Print the Index
df
輸出:
讓我們找到對索引進行排序的索引的順序。
# to find the ordering of indices
# that would sort the df Index
df.argsort()
輸出:
正如我們在輸出中看到的那樣,該函數已返回索引的順序,該順序將對給定的Index進行排序。我們可以通過基於順序打印索引來驗證這一點。
# Printing the Index based on the
# result of the argsort() function
df[df.argsort()]
輸出:
正如我們在輸出中看到的那樣,它是按排序順序打印的。
相關用法
- Python pandas.map()用法及代碼示例
- Python Pandas Series.str.len()用法及代碼示例
- Python Pandas.factorize()用法及代碼示例
- Python Pandas TimedeltaIndex.name用法及代碼示例
- Python Pandas dataframe.ne()用法及代碼示例
- Python Pandas Series.between()用法及代碼示例
- Python Pandas DataFrame.where()用法及代碼示例
- Python Pandas Series.add()用法及代碼示例
- Python Pandas.pivot_table()用法及代碼示例
- Python Pandas Series.mod()用法及代碼示例
- Python Pandas Dataframe.at[ ]用法及代碼示例
- Python Pandas Dataframe.iat[ ]用法及代碼示例
- Python Pandas.pivot()用法及代碼示例
- Python Pandas dataframe.mul()用法及代碼示例
- Python Pandas.melt()用法及代碼示例
注:本文由純淨天空篩選整理自Shubham__Ranjan大神的英文原創作品 Python | Pandas Index.argsort()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。