-4

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

Output: Output of the following code

  • 1
    Provide a sample of the input data, and explain what you want to achieve in the question and then people can help you with the code. – NYC Coder May 10 '20 at 13:34

1 Answers1

0

This should work

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

I don't know types of your dataframe so I converted them all to strings.

If you want to see more see this so question

joc
  • 179
  • 5