繁体   English   中英

大熊猫遍历每一行

[英]pandas iterating through each row

没有问题可以解决这一特定问题:

我想遍历数据框的行。 具体来说,在每一行中,我想按列名进行调用。 有没有办法做到这一点? 如果是这样,请示范。

我熟悉df[<column_name>][<index_name>] ,但是我认为这不能解决问题。 也许我可以将其与转置函数混合使用,但是随后我却无法掌握数据类型,对吗?

例如,如果我们有

    a b c d
 i1 1 1 2 1
 i2 2 2 1 1

我想能够说:

for f in some_iterator():
    print 'a is ' str(f['a'])
    print f['b'] + f['c']
    #skip f['d']

但就目前情况而言,我不能依靠列名来完成此操作,在这种情况下,请使用“ a,b,c,d”。

dfpandas.DataFrame对象。

我们可以通过以下方式遍历各行:

for row in df.iterrows():
    print str(row[0]) + " is the index of the row"
    print str(row[1]) + " is a series with rows having \
    labels the same as the columns of the dataframe"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM