<tfoot id='cLHWk'></tfoot>
    • <bdo id='cLHWk'></bdo><ul id='cLHWk'></ul>

  1. <legend id='cLHWk'><style id='cLHWk'><dir id='cLHWk'><q id='cLHWk'></q></dir></style></legend>
  2. <small id='cLHWk'></small><noframes id='cLHWk'>

  3. <i id='cLHWk'><tr id='cLHWk'><dt id='cLHWk'><q id='cLHWk'><span id='cLHWk'><b id='cLHWk'><form id='cLHWk'><ins id='cLHWk'></ins><ul id='cLHWk'></ul><sub id='cLHWk'></sub></form><legend id='cLHWk'></legend><bdo id='cLHWk'><pre id='cLHWk'><center id='cLHWk'></center></pre></bdo></b><th id='cLHWk'></th></span></q></dt></tr></i><div id='cLHWk'><tfoot id='cLHWk'></tfoot><dl id='cLHWk'><fieldset id='cLHWk'></fieldset></dl></div>

      如何在 Pandas 中遍历 DataFrame 中的行

      How to iterate over rows in a DataFrame in Pandas(如何在 Pandas 中遍历 DataFrame 中的行)

      <small id='qBRrl'></small><noframes id='qBRrl'>

    1. <i id='qBRrl'><tr id='qBRrl'><dt id='qBRrl'><q id='qBRrl'><span id='qBRrl'><b id='qBRrl'><form id='qBRrl'><ins id='qBRrl'></ins><ul id='qBRrl'></ul><sub id='qBRrl'></sub></form><legend id='qBRrl'></legend><bdo id='qBRrl'><pre id='qBRrl'><center id='qBRrl'></center></pre></bdo></b><th id='qBRrl'></th></span></q></dt></tr></i><div id='qBRrl'><tfoot id='qBRrl'></tfoot><dl id='qBRrl'><fieldset id='qBRrl'></fieldset></dl></div>

        <bdo id='qBRrl'></bdo><ul id='qBRrl'></ul>

            <legend id='qBRrl'><style id='qBRrl'><dir id='qBRrl'><q id='qBRrl'></q></dir></style></legend>
                <tbody id='qBRrl'></tbody>
              1. <tfoot id='qBRrl'></tfoot>

                本文介绍了如何在 Pandas 中遍历 DataFrame 中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!


                我有一个来自 Pandas 的 DataFrame:

                I have a DataFrame from Pandas:

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


                   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:

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

                在 Pandas 中可以做到这一点吗?

                Is it possible to do that in Pandas?

                我发现了这个 类似问题.但它并没有给我我需要的答案.例如,这里建议使用:

                I found this similar question. But it does not give me the answer I need. For example, it is suggested there to use:

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

                for row in df.iterrows():

                但我不明白 row 对象是什么以及如何使用它.

                But I do not understand what the row object is and how I can work with it.


                DataFrame.iterrows 是生成索引和行(作为系列)的生成器:

                DataFrame.iterrows is a generator which yields both the index and row (as a Series):

                import pandas as pd
                df = pd.DataFrame({'c1': [10, 11, 12], 'c2': [100, 110, 120]})
                df = df.reset_index()  # make sure indexes pair with number of rows
                for index, row in df.iterrows():
                    print(row['c1'], row['c2'])

                10 100
                11 110
                12 120

                这篇关于如何在 Pandas 中遍历 DataFrame 中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



                Split a Pandas column of lists into multiple columns(将 Pandas 的列表列拆分为多列)
                How does the @property decorator work in Python?(@property 装饰器在 Python 中是如何工作的?)
                What is the difference between old style and new style classes in Python?(Python中的旧样式类和新样式类有什么区别?)
                How to break out of multiple loops?(如何打破多个循环?)
                How to put the legend out of the plot(如何将传说从情节中剔除)
                Why is the output of my function printing out quot;Nonequot;?(为什么我的函数输出打印出“无?)
                    <bdo id='n5VVb'></bdo><ul id='n5VVb'></ul>
                      <tbody id='n5VVb'></tbody>
                    <i id='n5VVb'><tr id='n5VVb'><dt id='n5VVb'><q id='n5VVb'><span id='n5VVb'><b id='n5VVb'><form id='n5VVb'><ins id='n5VVb'></ins><ul id='n5VVb'></ul><sub id='n5VVb'></sub></form><legend id='n5VVb'></legend><bdo id='n5VVb'><pre id='n5VVb'><center id='n5VVb'></center></pre></bdo></b><th id='n5VVb'></th></span></q></dt></tr></i><div id='n5VVb'><tfoot id='n5VVb'></tfoot><dl id='n5VVb'><fieldset id='n5VVb'></fieldset></dl></div>

                        <small id='n5VVb'></small><noframes id='n5VVb'>

                        <tfoot id='n5VVb'></tfoot>
                          <legend id='n5VVb'><style id='n5VVb'><dir id='n5VVb'><q id='n5VVb'></q></dir></style></legend>