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

    1. <legend id='Cb2Oq'><style id='Cb2Oq'><dir id='Cb2Oq'><q id='Cb2Oq'></q></dir></style></legend>

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

        Pandas:更改通过列中的布尔索引选择的值而不会收到警告

        时间:2023-08-30
          <tbody id='opcPq'></tbody>

            <tfoot id='opcPq'></tfoot>

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

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

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

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

                  本文介绍了Pandas:更改通过列中的布尔索引选择的值而不会收到警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个数据框,我只想更改另一列满足特定条件的列的值.我目前正在尝试使用 iloc 执行此操作,但它要么不起作用,要么我收到了那个烦人的警告:

                  I have a dataframe, I want to change only those values of a column where another column fulfills a certain condition. I'm trying to do this with iloc at the moment and it either does not work or I'm getting that annoying warning:

                  试图在数据帧的切片副本上设置值

                  A value is trying to be set on a copy of a slice from a DataFrame

                  例子:

                  import pandas as pd
                  DF = pd.DataFrame({'A':[1,1,2,1,2,2,1,2,1],'B':['a','a','b','c','x','t','i','x','b']})
                  

                  做其中之一

                  DF['B'].iloc[:][DF['A'] == 1] = 'X'
                  
                  DF.iloc[:]['B'][DF['A'] == 1] = 'Y'
                  

                  有效,但会导致上述警告.

                  works, but leads to the warning above.

                  这个也给出警告,但不起作用:

                  This one also gives a warning, but does not work:

                  DF.iloc[:][DF['A'] == 1]['B'] = 'Z'
                  

                  我真的很困惑如何使用locilocix做布尔索引对,也就是如何提供行索引、列索引和布尔索引以正确的顺序和正确的语法.

                  I'm really confused about how to do boolean indexing using loc, iloc, and ix right, that is, how to provide row index, column index, AND boolean index in the right order and with the correct syntax.

                  谁能帮我解决这个问题?

                  Can someone clear this up for me?

                  推荐答案

                  你正在链接你的选择器,导致警告.将所选内容合并为一个.
                  改用 loc

                  You are chaining you're selectors, leading to the warning. Consolidate the selection into one.
                  Use loc instead

                  DF.loc[DF['A'] == 1, 'B'] = 'X'
                  DF
                  

                  这篇关于Pandas:更改通过列中的布尔索引选择的值而不会收到警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在给定条件下生成所有可能的组合以提高效率? 下一篇:Ruby 是否支持条件正则表达式

                  相关文章

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

                      <tfoot id='R9Jgp'></tfoot>
                    1. <small id='R9Jgp'></small><noframes id='R9Jgp'>

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