• <small id='8ICiM'></small><noframes id='8ICiM'>

    • <bdo id='8ICiM'></bdo><ul id='8ICiM'></ul>

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

        if else 不检查 Python 中的两个条件

        时间:2023-08-30
        <legend id='0F0sz'><style id='0F0sz'><dir id='0F0sz'><q id='0F0sz'></q></dir></style></legend>

            • <bdo id='0F0sz'></bdo><ul id='0F0sz'></ul>

              1. <tfoot id='0F0sz'></tfoot>
              2. <i id='0F0sz'><tr id='0F0sz'><dt id='0F0sz'><q id='0F0sz'><span id='0F0sz'><b id='0F0sz'><form id='0F0sz'><ins id='0F0sz'></ins><ul id='0F0sz'></ul><sub id='0F0sz'></sub></form><legend id='0F0sz'></legend><bdo id='0F0sz'><pre id='0F0sz'><center id='0F0sz'></center></pre></bdo></b><th id='0F0sz'></th></span></q></dt></tr></i><div id='0F0sz'><tfoot id='0F0sz'></tfoot><dl id='0F0sz'><fieldset id='0F0sz'></fieldset></dl></div>
                  <tbody id='0F0sz'></tbody>
              3. <small id='0F0sz'></small><noframes id='0F0sz'>

                  本文介绍了if else 不检查 Python 中的两个条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我希望根据特定条件创建新列 ['pred_n'],条件如下:如果年份小于或等于当前年份 &月份小于当前月份,pred_n 应等于 yhatpct,否则应为 yhatpct_ft.尝试以下语法:

                  i want new column ['pred_n'] to be created based on certain condition, condition is as follows: if year is less than or equal to current year & month is less than current month, pred_n should be equal to yhatpct else it should be yhatpct_ft. trying following syntax:

                  if((dfyz['year_x'] < datetime.now().year) | ((dfyz['year_x'] == datetime.now().year) & (dfyz['mon'] < datetime.now().month))):
                      dfyz['pred_n'] = dfyz['yhat']*dfyz['pct']
                  else:
                      dfyz['pred_n'] = dfyz['yhat']*dfyz['pct_ft']
                  

                  但只有在我的数据中有从 2019 年到 08 年开始的月份和年份时,才会显示输出如果我使用

                  but output shows only if condition though in my data I have month and year from 2019 - 08 onwards and if i use

                  if ((dfyz['year_x'] < datetime.now().year) | ((dfyz['year_x'] == datetime.now().year) & (dfyz['mon'] < datetime.now().month))):
                       dfyz['pred_n'] = dfyz['yhat']*dfyz['pct']
                  elif (((dfyz['year_x'] == datetime.now().year) & (dfyz['mon'] >= datetime.now().month)) | ((dfyz['year_x'] > datetime.now().year))):
                         dfyz['pred_n'] = dfyz['yhat']*dfyz['pct_ft']
                  

                  它只在 else 条件下给出输出

                  it gives output only for else condition

                  推荐答案

                  您目前正在使用 bitwise 运算符 |&,而不是 logical 运算符 orand.大概你真的想要这样的东西:

                  You are currently using the bitwise operators | and &, rather than the logical operators orand and. Presumably you really want something like:

                  now = datetime.now()
                  if (dfyz['year_x'] < now.year or        
                      dfyz['year_x'] == now.year and dfyz['mon'] < now.month
                  ):
                      ...
                  

                  (继续多次调用 now 并不是很好的做法......您的每个调用现在都可能返回一个 不同 值)

                  (Its not great practice to keep calling now several times ... each of your calls is potentially returning a different value for now)

                  这篇关于if else 不检查 Python 中的两个条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:基于 if-else 条件和查找创建新的 pandas 数据框列 下一篇:Python:base64解码时忽略“不正确的填充"错误

                  相关文章

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

                • <small id='DS74K'></small><noframes id='DS74K'>

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