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.

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

4 Comments

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
Thankyou - I will try this later and will be sure to update the best answer when I get home :)
@Slippy please accept the answer (click the check mark next to the answer) if it answered your question.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.