【问题标题】:How will I write an equivalent Python syntax for R syntax我将如何为 R 语法编写等效的 Python 语法
【发布时间】:2020-08-25 23:24:32
【问题描述】:

data$GroupId = paste(data$Surname, data$Pclass, sub('.$','X',data$Ticket), data$Fare, data$Embarked, sep='-')

输出: Output of the following code

【问题讨论】:

  • 提供输入数据的样本,并在问题中说明您想要实现的目标,然后人们可以帮助您编写代码。

标签: r python-3.x pandas join regexp-replace


【解决方案1】:

这应该可以工作

data['GroupId'] = data['Surname'] + data['Pclass'].astype(str).str.replace('$', 'X') + '-' + data['Fare'].astype(str) + data['Embarked'].astype(str)

我不知道你的数据框的类型,所以我将它们全部转换为字符串。

如果你想看更多see this so question

【讨论】:

  • 很高兴听到。然后您可以关闭问题。
猜你喜欢
  • 1970-01-01
  • 2020-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-06
  • 2016-08-05
相关资源
最近更新 更多