Cooper Xiong Cooper Xiong - 4 months ago 7
Python Question

pandas,how to get the index after using the func pandas.Series.value_counts?

there is my code
..

code_c = data.code.value_counts()
print code_c
ss = code_c.loc[code_c.values == 15]
print ss


get:

>>>code_c
600644 16
600101 16
600652 15
600256 15
717 15
600282 15
543 15
709 15
..
2352 5
2478 5
2379 5
>>>ss
600652 15
600256 15
807 15
600868 15
531 15
795 15
600188 15
..


I have the trouble getting the list(600652,600256,807,600686,...)
Can you help me?thanks a lot.

Answer

You can get the index via the index attribute.

ss.index.tolist()  # to return a list

or

# to return a pandas series with index values as series values
ss.index.to_series()