how to convert pandas series to tuple of index and value

Well it seems simply zip(s,s.index) works too!

For Python-3.x, we need to wrap it with list

list(zip(s,s.index))

To get a tuple of tuples, use tuple() : tuple(zip(s,s.index)).

Sample run –

In [8]: s
Out[8]: 
a    1
b    2
c    3
dtype: int64

In [9]: list(zip(s,s.index))
Out[9]: [(1, 'a'), (2, 'b'), (3, 'c')]

In [10]: tuple(zip(s,s.index))
Out[10]: ((1, 'a'), (2, 'b'), (3, 'c'))

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)