Pandas 系列 - 打印列和行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24356270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 22:11:04  来源:igfitidea点击:

Pandas Series - print columns and rows

python-2.7pandasscipy

提问by Slippy

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 循环来迭代这个,例如:

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.

非常感谢所有帮助,我对Pandas很陌生,并且遇到了一些出牙问题。

Thanks.

谢谢。

采纳答案by bananafish

Try Series.iteritems.

试试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