Python | Pandas Index.searchsorted() Last Updated : 18 Jan, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.Pandas Index.searchsorted() function find indices where elements should be inserted to maintain order. The function find the indices into a sorted IndexOpsMixin self such that, if the corresponding elements in value were inserted before the indices, the order of self would be preserved. Syntax: Index.searchsorted(value, side='left', sorter=None)Parameters : value : Values to insert into self. side : If ‘left’, the index of the first suitable location found is given. If ‘right’, return the last such index. If there is no suitable index, return either 0 or N (where N is the length of self). sorter : Optional array of integer indices that sort self into ascending order. They are typically the result of np.argsort.Returns : [indices : array of ints] Array of insertion points with the same shape as value. Example #1: Use Index.searchsorted() function to find the correct position to insert an element such that the Index remains sorted. Python3 # importing pandas as pd import pandas as pd # Creating the index idx = pd.Index([1, 5, 8, 9, 11, 24, 56, 81]) # Print the Index idx Output : Let's find the position of for insertion if the element to be inserted is 10 Python3 # to find the position of insertion idx.searchsorted(10) Output : As we can see in the output, the function has returned 4 indicating that the correct position to insert 10 in the index is 4 if the order is to be maintained. Example #2: Use Index.searchsorted() function to find the correct position of insertion for more than one elements in the Index. The insertion should be done such that the order is maintained. Python3 # importing pandas as pd import pandas as pd # Creating the index idx = pd.Index([1, 5, 8, 9, 11, 24, 56, 81]) # Print the Index idx Output : Let's find the position of for insertion if the element to be inserted is 7 and 29 Python3 # to find the position of insertion idx.searchsorted([7, 29]) Output : As we can see in the output, the function has returned 2 and 6 indicating that the correct position to insert 7 and 29 in the index is 2nd and 6th position if the order is to be maintained. Comment More infoAdvertise with us Next Article Python | Pandas Index.shape S Shubham__Ranjan Follow Improve Article Tags : Technical Scripter Python Python-pandas Python pandas-indexing Practice Tags : python Similar Reads Python | Pandas Series.sort_index() Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Pandas Series.sort_index() function is used 2 min read Python | Pandas Index.where Pandas Index is an immutable ndarray implementing an ordered, sliceable set. It is the basic object which stores the axis labels for all pandas objects. Pandas Index.where function return an Index of same shape as self and whose corresponding entries are from self where cond is True and otherwise ar 2 min read Python | Pandas Series.str.index() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas str.index() method is used to search and return lowest index of a substring in 3 min read Python | Pandas Series.str.index() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas str.index() method is used to search and return lowest index of a substring in 3 min read Python | Pandas Index.shape Pandas Index is an immutable ndarray implementing an ordered, sliceable set. It is the basic object which stores the axis labels for all pandas objects. Pandas Index.shape attribute return a tuple of the shape of the underlying data in the given Index object. Syntax: Index.shape Parameter : None Ret 2 min read Python | Pandas Series.searchsorted() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas searchsorted() is a method for sorted series. It allows user to pass values as 2 min read Like