Python | Pandas Index.difference() Last Updated : 31 Aug, 2021 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.difference() function return a new Index with elements from the index that are not in other. The function automatically sorts the output if sorting is possible. Syntax: Index.difference(other)Parameters : other : Index or array-likeReturns : difference : Index Example #1: Use Index.difference() function to find the set difference of a given Index with an array-like object. Python3 # importing pandas as pd import pandas as pd # Creating the Index idx = pd.Index([17, 69, 33, 15, 19, 74, 10, 5]) # Print the Index idx Output : Let's find the set difference of the given Index with an array-like object Python3 # find the set difference of this Index # with the passed array object. idx.difference([69, 33, 15, 74, 19]) Output : As we can see in the output, the function has returned an object which contains only those values which are unique to the idx Index.Note that the output object has its element sorted in Increasing order. Example #2: Use Index.difference() function to find the set difference of two Indexes. Python3 # importing pandas as pd import pandas as pd # Creating the first Index idx1 = pd.Index(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']) # Creating the second Index idx2 = pd.Index(['May', 'Jun', 'Jul', 'Aug']) # Print the first and second Index print(idx1, "\n", idx2) Output : Now, let's find the set difference between two Indexes. Python3 # to find the set difference idx1.difference(idx2) Output : The function has returned the set difference of idx1 and idx2. It contains only those values which are unique to idx1 Index. Note that the output is not sorted. Comment More infoAdvertise with us Next Article Python | Pandas Index.identical() S Shubham__Ranjan Follow Improve Article Tags : Technical Scripter Python Python-pandas Python pandas-indexing Practice Tags : python Similar Reads Python | Pandas Index.delete() 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.delete() function returns a new object with the passed locations deleted. 2 min read Python | Pandas Index.identical() 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.identical() function determine if two Index objects contains the same ele 2 min read Python | Pandas Index.to_frame() 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.to_frame() function create a dataFrame from the given index with a column 2 min read Python | Pandas Index.asof() 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.asof() function returns return the label from the index, or, if not prese 2 min read Python | Pandas Index.copy() 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.copy() function make a copy of this object. The function also sets the na 2 min read Python | Pandas Index.data 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.data attribute return the data pointer of the underlying data of the given Index object. Syntax: Index.data Parameter : None Returns : 2 min read Like