Pandas - Creating a New Column

前端 未结 1 629
旧巷少年郎
旧巷少年郎 2021-02-04 17:44

I have always made new columns in pandas using the following:

df[\'new_column\'] = value

I am using this method, however, am receiving the warn

相关标签:
1条回答
  • 2021-02-04 18:29

    Try using

    df.loc[:,'new column'] = value
    

    As piRSquared comments, dfis probably a copy of another DataFrame and when you set values to df it probably incurs in what is called chain indexing. Refer to pandas docs for further information.

    0 讨论(0)
提交回复
热议问题