“Pandorable” way to return index in dataframe slicing
问题 Is there a pandorable way to get only the index in dataframe slicing? In other words, is there a better way to write the following code: df.loc[df['A'] >5].index Thanks! 回答1: Yes, better is filter only index values, not all DataFrame and then select index: #filter index df.index[df['A'] >5] #filter DataFrame df[df['A'] >5].index Difference is in performance too: np.random.seed(1245) df = pd.DataFrame({'A':np.random.randint(10, size=1000)}) print (df) In [40]: %timeit df.index[df['A'] >5] 208