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

  • 问题描述

    df['new_column'] = df['old_column']

    上述命令导致如题问题。

  • 解决方案

    涉及Python底层数据处理,关键字: __getitem__chained indexing

    简单来讲的话,尽量用df.loc[行名, 列名] = 值方式赋值,不采用df[][]方式赋值。

  • Reference

  1. Pandas - A value is trying to be set on a copy of a slice from a DataFrame

你可能感兴趣的:(Error,Record,#,小白学Python,copywarning,pandas,loc)