step-by-by-step errod reproduction
最初,没有警告。但是,基于DF的子集创建一个新的数据帧: new_df = df.loc [df.col1> 2] ,然后尝试使用.loc修改新的数据frame:
new_df.loc [2,'new_column'] = 100解决方案:使用.copy()用于从子集
new_df_copy = df.loc [df.col1>> 2] .copy() new_df_copy.loc[2, 'new_column'] = 100By invoking .copy(), you create an independent copy of the subset, avoiding the warning when modifying values.
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3