pandas 系列-打印列和行 [英] Pandas Series - print columns and rows
本文介绍了 pandas 系列-打印列和行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
就目前而言,我并不担心最有效的方式来获取系列中的数据,可以说我的系列如下:
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
如果我使用for循环来对此进行迭代,例如:
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.
谢谢.
推荐答案
尝试 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
打印:
A 1
B 2
C 3
D 4
这篇关于 pandas 系列-打印列和行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文