4

For now I am not so worried about the most performant way to get at my data in a series, lets say that my series is as follows :

A  1
B  2
C  3
D  4

If I am using a for loop to iterate this, for example :

for row in seriesObj:
    print row

The code above will print the values down the right hand side, but lets say, I want to get at the left column (indexes) how might I do that?

All help greatly appreciated, I am very new to pandas and am having some teething problems.

Thanks.

Slippy
  • 1,253
  • 5
  • 22
  • 43

1 Answers1

5

Try Series.iteritems.

import pandas as pd

s = pd.Series([1, 2, 3, 4], index=iter('ABCD'))

for ind, val in s.iteritems():
    print ind, val

Prints:

A 1
B 2
C 3
D 4
bananafish
  • 2,877
  • 20
  • 29
  • Ah cool, thanks, and how might I then decide to get the index alone each time or the value? Like, say I wanted to have key = row_key data = row_data – Slippy Jun 23 '14 at 08:53
  • Thankyou - I will try this later and will be sure to update the best answer when I get home :) – Slippy Jun 24 '14 at 09:50
  • @Slippy please accept the answer (click the check mark next to the answer) if it answered your question. – bananafish Jun 25 '14 at 21:51
  • Sorry for the late response - I have been so damn busy with work this week that I forgot to sign in - your help has been greatly appreciated. – Slippy Jun 28 '14 at 19:36