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

      1. <tfoot id='sKY7u'></tfoot>
      2. <small id='sKY7u'></small><noframes id='sKY7u'>

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

      3. Pandas 对数据框的布尔比较

        Pandas boolean comparisson on dataframe(Pandas 对数据框的布尔比较)

        1. <small id='LQIK8'></small><noframes id='LQIK8'>

          1. <legend id='LQIK8'><style id='LQIK8'><dir id='LQIK8'><q id='LQIK8'></q></dir></style></legend>
            <i id='LQIK8'><tr id='LQIK8'><dt id='LQIK8'><q id='LQIK8'><span id='LQIK8'><b id='LQIK8'><form id='LQIK8'><ins id='LQIK8'></ins><ul id='LQIK8'></ul><sub id='LQIK8'></sub></form><legend id='LQIK8'></legend><bdo id='LQIK8'><pre id='LQIK8'><center id='LQIK8'></center></pre></bdo></b><th id='LQIK8'></th></span></q></dt></tr></i><div id='LQIK8'><tfoot id='LQIK8'></tfoot><dl id='LQIK8'><fieldset id='LQIK8'></fieldset></dl></div>
            • <bdo id='LQIK8'></bdo><ul id='LQIK8'></ul>
              <tfoot id='LQIK8'></tfoot>
                  <tbody id='LQIK8'></tbody>
                • 本文介绍了Pandas 对数据框的布尔比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当我对数据框中的单个元素进行比较时出现错误,但我不明白为什么.

                  I am getting the error when I make a comparison on a single element in a dataframe, but I don't understand why.

                  我有一个数据框 df,其中包含许多客户的时间序列数据,其中包含一些空值:

                  I have a dataframe df with timeseries data for a number of customers, with some null values within it:

                  df.head()
                                      8143511  8145987  8145997  8146001  8146235  8147611  
                  2012-07-01 00:00:00      NaN      NaN      NaN      NaN      NaN      NaN   
                  2012-07-01 00:30:00    0.089      NaN    0.281    0.126    0.190    0.500   
                  2012-07-01 01:00:00    0.090      NaN    0.323    0.141    0.135    0.453   
                  2012-07-01 01:30:00    0.061      NaN    0.278    0.097    0.093    0.424   
                  2012-07-01 02:00:00    0.052      NaN    0.278    0.158    0.170    0.462  
                  

                  在我的脚本中,行if pd.isnull(df[[customer_ID]].loc[ts]):产生错误:

                  In my script, the line if pd.isnull(df[[customer_ID]].loc[ts]): generates an error:

                  ValueError: Series 的真值不明确.使用 a.empty、a.bool()、a.item()、a.any() 或 a.all().

                  但是,如果我在脚本行设置断点,并且当脚本停止时,我会在控制台中输入:

                  However, if I put a breakpoint on the line of script, and when the script stops I type this into the console:

                  pd.isnull(df[[customer_ID]].loc[ts])
                  

                  输出是:

                  8143511    True
                  Name: 2012-07-01 00:00:00, dtype: bool
                  

                  如果我允许脚本从该点继续,则会立即生成错误.

                  If I allow the script to continue from that point, the error is generated immediately.

                  如果布尔表达式可以求值并且值为True,为什么它会在if 表达式中产生错误?这对我来说毫无意义.

                  If the boolean expression can be evaluated and has the value True, why does it generate an error in the if expression? This makes no sense to me.

                  推荐答案

                  第二组 [] 正在返回一个我误认为是单个值的系列.最简单的解决方案是删除 []:

                  The second set of [] was returning a series which I mistook for a single value. The simplest solution is to remove []:

                  if pd.isnull(df[customer_ID].loc[ts]):
                         pass
                  

                  这篇关于Pandas 对数据框的布尔比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                      <tfoot id='s9yIn'></tfoot>
                      <legend id='s9yIn'><style id='s9yIn'><dir id='s9yIn'><q id='s9yIn'></q></dir></style></legend>
                          <tbody id='s9yIn'></tbody>
                      1. <small id='s9yIn'></small><noframes id='s9yIn'>

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