最佳实践在自定义功能中创建熊猫列

发布于 2025-01-26 12:26:07 字数 313 浏览 2 评论 0原文

假设我有一个熊猫数据框和一个笔记本单元,我添加了一列:

df[col_3] = df[col1]+df[col2]

什么是最好的(最有效,最类似于Pep8,最简单的,最可读的)方法,可以在helpfile中创建它作为函数。 helpfunctions.py ?

我的方法只是是

def create_col3:
    df[col_3] = df[col1]+df[col2]

,但我不确定这是否是一种可以接受的方法,还是有更好的方法。

Assumed I have a pandas data frame and a notebook cell where I add a column:

df[col_3] = df[col1]+df[col2]

What is the best (most efficient, most pep8-like and/or simplest, most readable) way to create this as a function within a helpfile helpfunctions.py?

My approach would just be

def create_col3:
    df[col_3] = df[col1]+df[col2]

but I am not sure whether this is even an acceptable way or whether there is a better way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文