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

    1. <tfoot id='6hFaq'></tfoot>

      <small id='6hFaq'></small><noframes id='6hFaq'>

        <bdo id='6hFaq'></bdo><ul id='6hFaq'></ul>
      <legend id='6hFaq'><style id='6hFaq'><dir id='6hFaq'><q id='6hFaq'></q></dir></style></legend>

      1. 当你比较 2 个 pandas 系列时会发生什么

        What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
              <tbody id='YNi1v'></tbody>

              <legend id='YNi1v'><style id='YNi1v'><dir id='YNi1v'><q id='YNi1v'></q></dir></style></legend>

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

            1. <tfoot id='YNi1v'></tfoot>
                <bdo id='YNi1v'></bdo><ul id='YNi1v'></ul>
                1. <i id='YNi1v'><tr id='YNi1v'><dt id='YNi1v'><q id='YNi1v'><span id='YNi1v'><b id='YNi1v'><form id='YNi1v'><ins id='YNi1v'></ins><ul id='YNi1v'></ul><sub id='YNi1v'></sub></form><legend id='YNi1v'></legend><bdo id='YNi1v'><pre id='YNi1v'><center id='YNi1v'></center></pre></bdo></b><th id='YNi1v'></th></span></q></dt></tr></i><div id='YNi1v'><tfoot id='YNi1v'></tfoot><dl id='YNi1v'><fieldset id='YNi1v'></fieldset></dl></div>
                  本文介绍了当你比较 2 个 pandas 系列时会发生什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在比较两个系列时,我遇到了 pandas 的意外行为.我想知道这是故意的还是错误的.

                  I ran up against unexpected behavior in pandas when comparing two series. I wanted to know if this is intended or a bug.

                  假设我:

                  import pandas as pd
                  x = pd.Series([1, 1, 1, 0, 0, 0], index=['a', 'b', 'c', 'd', 'e', 'f'], name='Value')
                  y = pd.Series([0, 2, 0, 2, 0, 2], index=['c', 'f', 'a', 'e', 'b', 'd'], name='Value')
                  
                  x > y
                  

                  产量:

                  a     True
                  b    False
                  c     True
                  d    False
                  e    False
                  f    False
                  Name: Value, dtype: bool
                  

                  这不是我想要的.显然,我预计指数会排成一行.但是我必须明确地将它们排列起来才能得到想要的结果.

                  which isn't what I wanted. Clearly, I expected the indexes to line up. But I have to explicitly line them up to get the desired results.

                  x > y.reindex_like(x)
                  

                  产量:

                  a     True
                  b     True
                  c     True
                  d    False
                  e    False
                  f    False
                  Name: Value, dtype: bool
                  

                  这是我所期望的.

                  更糟糕的是,如果我:

                  x + y
                  

                  我明白了:

                  a    1
                  b    1
                  c    1
                  d    2
                  e    2
                  f    2
                  Name: Value, dtype: int64
                  

                  所以在操作时,索引排成一行.比较时,他们没有.我的观察准确吗?这是出于某种目的吗?

                  So when operating, the indexes line up. When comparing, they do not. Is my observation accurate? Is this intended for some purpose?

                  谢谢,

                  -PiR

                  推荐答案

                  Bug 与否.我建议制作一个数据框并比较数据框内的系列.

                  Bug or not. I would suggest to make a dataframe and compare the series inside the dataframe.

                  import pandas as pd
                  x = pd.Series([1, 1, 1, 0, 0, 0], index=['a', 'b', 'c', 'd', 'e', 'f'], name='Value_x')
                  y = pd.Series([0, 2, 0, 2, 0, 2], index=['c', 'f', 'a', 'e', 'b', 'd'], name='Value_y')
                  
                  df = pd.DataFrame({"Value_x":x, "Value_y":y})
                  df['Value_x'] > df['Value_y']
                  
                  Out[3]:
                  
                  a     True
                  b     True
                  c     True
                  d    False
                  e    False
                  f    False
                  dtype: bool
                  

                  这篇关于当你比较 2 个 pandas 系列时会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                  Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                  Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                  Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                  Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)
                  removing an instance of an object in python list(删除python列表中的对象实例)

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

                      • <i id='G6cBl'><tr id='G6cBl'><dt id='G6cBl'><q id='G6cBl'><span id='G6cBl'><b id='G6cBl'><form id='G6cBl'><ins id='G6cBl'></ins><ul id='G6cBl'></ul><sub id='G6cBl'></sub></form><legend id='G6cBl'></legend><bdo id='G6cBl'><pre id='G6cBl'><center id='G6cBl'></center></pre></bdo></b><th id='G6cBl'></th></span></q></dt></tr></i><div id='G6cBl'><tfoot id='G6cBl'></tfoot><dl id='G6cBl'><fieldset id='G6cBl'></fieldset></dl></div>
                      • <legend id='G6cBl'><style id='G6cBl'><dir id='G6cBl'><q id='G6cBl'></q></dir></style></legend>
                          <tbody id='G6cBl'></tbody>

                          <tfoot id='G6cBl'></tfoot>
                            <bdo id='G6cBl'></bdo><ul id='G6cBl'></ul>