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

    • <bdo id='CozNd'></bdo><ul id='CozNd'></ul>
    1. <small id='CozNd'></small><noframes id='CozNd'>

      1. 使用 copy() 后的 SettingWithCopyWarning

        时间:2023-08-29

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

              <bdo id='MMihX'></bdo><ul id='MMihX'></ul>
                <tbody id='MMihX'></tbody>

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

                1. 本文介绍了使用 copy() 后的 SettingWithCopyWarning的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的代码如下.

                  import pandas as pd
                  import numpy as np
                  data = [['Alex',10,5,0],['Bob',12,4,1],['Clarke',13,6,0],['brke',15,1,0]]
                  df = pd.DataFrame(data,columns=['Name','Age','weight','class'],dtype=float) 
                  
                  df_numeric=df.select_dtypes(include='number')#, exclude=None)[source]
                  df_non_numeric=df.select_dtypes(exclude='number')
                  
                  df_non_numeric['class']=df_numeric['class'].copy()
                  

                  它给了我下面的信息

                  __main__:1: SettingWithCopyWarning: 
                  A value is trying to be set on a copy of a slice from a DataFrame.
                  Try using .loc[row_indexer,col_indexer] = value instead
                  
                  See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
                  

                  我想让 df_non_numeric 独立于 df_numeric

                  我根据其他帖子中的建议使用了 df_numeric['class'].copy().

                  i used df_numeric['class'].copy() based upon suggestions given in other posts.

                  我怎样才能避免这条消息?

                  How could i avoid the message?

                  推荐答案

                  我认为你需要 copy 因为 DataFrame.select_dtypes 是切片操作,按列类型过滤,勾选问题3:

                  I think you need copy because DataFrame.select_dtypes is slicing operation, filtering by types of column, check Question 3:

                  df_numeric=df.select_dtypes(include='number').copy()
                  df_non_numeric=df.select_dtypes(exclude='number').copy()
                  

                  如果您稍后修改 df_non_numeric 中的值,您会发现修改不会传播回原始数据 (df),并且 Pandas 会发出警告.

                  If you modify values in df_non_numeric later you will find that the modifications do not propagate back to the original data (df), and that Pandas does warning.

                  这篇关于使用 copy() 后的 SettingWithCopyWarning的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 Python 中强制复制一个小 int 下一篇:试图在来自 DF 的切片副本上设置值

                  相关文章

                2. <tfoot id='V5mJp'></tfoot>

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

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