Get pandas series index in data

Viewed 1676

I want to format a series of strings so the index is in the string somewhere. Example series:

ser = pd.Series(['CT', 'NY', 'MT'], index=['Jessica', 'Eric', 'Toby'])
ser
Jessica    CT
Eric       NY
Toby       MT
dtype: object

The desired output:

Jessica    Jessica: CT
Eric          Eric: NY
Toby          Toby: MT
dtype: object

I've tried variants of this:

ser.apply(lambda x: "{}: {}".format(x.index, x))

but it doesn't work because x.index refers to the index method of str, not the series being iterated over.

1 Answers
Related