import pandas as pd
series = pd.Series(['a', 'b', 'c', 'a', 'a'])
print(dict((v, i) for i, v in enumerate(series.value_counts().index)))
结果:
{'a': 0, 'b': 1, 'c': 2}
import pandas as pd
series = pd.Series(['a', 'b', 'c', 'a', 'a'])
print(dict((v, i) for i, v in enumerate(series.value_counts().index)))
结果:
{'a': 0, 'b': 1, 'c': 2}