在 dask 中的 if-else 之后创建一个新列

发布于 2025-01-12 21:47:36 字数 341 浏览 2 评论 0原文

df['new_col'] = np.where(df['col1'] == df['col2'] , True, False),其中 col1 和 col2 都是 str 数据类型,看起来很漂亮直接向前。在 if else 语句之后在 dask 中创建列的更有效方法是什么?我尝试了此建议 在中创建 if-else 条件列dask dataframe 但这需要很长时间。大约一个小时后,它只处理了大约 30%。我有 1300 万行和 70 列

df[‘new_col’] = np.where(df[‘col1’] == df[‘col2’] , True, False), where col1 and col2 are both str data types, seems pretty straight forward. What is the more efficient method to create a column in dask after an if else statement? I tried the recommendation from this Create an if-else condition column in dask dataframe but it is taking forever. It has only processed about 30% after about an hour. I have 13mil rows and 70 columns

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

握住你手 2025-01-19 21:47:36

如果需要将列设置为布尔值,则使用 IIUC:

df['new_col'] = df['col1'] == df['col2']

如果需要设置为其他值:

df['new_col'] = 'val for true'
ddf = df.assign(col1 = df.new_col.where(cond=df['col1'] == df['col2'], other='val for false'))

IIUC use if need set column to boolean:

df['new_col'] = df['col1'] == df['col2']

If need set to another values:

df['new_col'] = 'val for true'
ddf = df.assign(col1 = df.new_col.where(cond=df['col1'] == df['col2'], other='val for false'))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文