xs
Used in multiple indexes, first create a dataframe with a secondary row index, as shown below:
np.arrays = [['one', 'one', 'one', 'two', 'two', 'two'], [1, 2, 3, 1, 2, 3]] df = pd.DataFrame(np.random.randn(6, 2), index = pd.MultiIndex.from_tuples(list(zip(*np.arrays))), columns = ['A', 'B']) df
The data set is displayed as follows:
Use df.loc[‘one’]
Use df.xs(‘one’)
Use df .xs(('one', 1))
Use the loc
method
The above is the detailed content of How to use xs in DataFrame in Python. For more information, please follow other related articles on the PHP Chinese website!