如何在Pandas的DataFrame中的行上進行迭代? - How to iterate over rows in a DataFrame in Pandas?

問題:

I have a DataFrame from pandas: 我有一個來自熊貓的DataFrame 框架

import pandas as pd
inp = [{'c1':10, 'c2':100}, {'c1':11,'c2':110}, {'c1':12,'c2':120}]
df = pd.DataFrame(inp)
print df

Output: 輸出: oop

c1   c2
0  10  100
1  11  110
2  12  120

Now I want to iterate over the rows of this frame. 如今,我要遍歷該框架的行。 For every row I want to be able to access its elements (values in cells) by the name of the columns. 對於每一行,我但願可以經過列名訪問其元素(單元格中的值)。 For example: 例如: this

for row in df.rows:
   print row['c1'], row['c2']

Is it possible to do that in pandas? 熊貓有可能這樣作嗎? spa

I found this similar question . 我發現了相似的問題 But it does not give me the answer I need. 但這並不能給我我所需的答案。 For example, it is suggested there to use: 例如,建議在那裏使用: .net

for date, row in df.T.iteritems():

or 要麼 code

for row in df.iterrows():

But I do not understand what the row object is and how I can work with it. 可是我不明白什麼是row對象以及如何使用它。 對象


解決方案:

參考一: https://stackoom.com/question/178Oq/如何在Pandas的DataFrame中的行上進行迭代
參考二: https://oldbug.net/q/178Oq/How-to-iterate-over-rows-in-a-DataFrame-in-Pandas
相關文章
相關標籤/搜索