Pandas Series - Printing Columns and Rows

While I'm not so worried about the most efficient way to get my data in a series, let's say my series looks like this:

A  1
B  2
C  3
D  4

If I use a for loop to iterate, for example:

for row in seriesObj:
    print row

The above code will print the values ​​on the right side, but lets say what I want in the left column (indexes), how can I do this?

All help is much appreciated, I am very new to pandas and I have problems with slots.

Thank.

+4
source share
1 answer

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

Print

A 1
B 2
C 3
D 4
+4
source

Source: https://habr.com/ru/post/1545596/


All Articles