示例页面

pandas-assign函数

尽管df["column"]方式新增一列数据已经很方便,但是在不需要实际生成该列,又可以调用某列数据时,df.assign()方法更具优势。

创建数据:

新增列:df["column"]

新增列:df.assign()

assign always returns a copy of the data, leaving the original DataFrame untouched.

使用assign方法返回数据的副本,原始数据不受影响。

You can create multiple columns within the same assign where one of the columns depends on another one defined within the same assign.

在同一个assign中创建多列,下一列数据创建过程可以直接调用刚生成的上一列。

posted @ 2022-04-08 17:32  没有风格的Wang  阅读(771)  评论(0编辑  收藏  举报