gpt4 book ai didi

python - 添加字符串 + 自动递增 - pandas, python

转载 作者:太空宇宙 更新时间:2023-11-03 14:57:27 25 4
gpt4 key购买 nike

如果另一列为空,我需要更新数据框中的一列。该列是“subscriberkey”并且其中已经有值。我需要用字符串 + 数字更新这些值。我的意图不是创建重复的列。

值必须是唯一的,因此我最初认为附加字符串+数字是可行的方法。

Age Email            Subscriberkey
10 john@google.com giririfndfieir
23 kfkkfkfffrrrc
64 jane@ibm.co.uk ifiririieiriei

对于第二行,我希望 subscriberkey 是 string+number+string到目前为止,我已经尝试了以下方法:

 df.loc[df.Email == NULL, 'subscriberkey']= 'string'+.cumcount()+1+'string'

我会很感激关于如何最好地实现这一目标的指示。

最佳答案

你可以尝试这样的事情:

nullCond = df.Email.isnull()    
# or nullCond = (df.Email == "") it those are empty strings

df.loc[nullCond, 'Subscriberkey'] = "string" + nullCond[nullCond].cumsum().astype(str) + "string"

enter image description here

关于python - 添加字符串 + 自动递增 - pandas, python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41365014/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com