0

The given data frame 'customer' has a column 'Cust_id' which has values Cust_1, Cust_2 and so on. Remove the repeated 'Cust_' from the column Cust_id so that the output column Cust_id have just numbers like 1, 2, 3 and so on.

e.g. Column Heading is "Customer Info"

CUSTOMET INFO

Cust_1 Cust_2 Cust_3 * * * * Cust_100

Desired Output is:

CUSTOMET INFO

1 2 3 4 * * * * 100

  • Does this answer your question? [Pandas: how to change all the values of a column?](https://stackoverflow.com/questions/12604909/pandas-how-to-change-all-the-values-of-a-column) – suraj deshmukh Jun 08 '21 at 07:04

4 Answers4

0

You can use the apply function:

df = pd.DataFrame(["Cust_1", "Cust_2", "Cust_3"], columns=["CustomerID"])
df.CustomerID = df.CustomerID.apply(lambda x: x[5:])
YuserT
  • 16
  • 2
0
data['Cust_id'] = data['Cust_id'].map(lambda x: x.lstrip('Cust_'))
NabaaJafar
  • 13
  • 1
  • 7
0

Cust_id = customer['Cust_id']
l = [x[5:] for x in Cust_id]
customer['Cust_id'] = l
customer

  • It would be better if the code is formated in a code block. – Park Jan 23 '22 at 13:39
  • While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Yunnosch Feb 24 '22 at 21:45
0

You can simply use string function to remove the Cust_ part of the string:

customer['Cust_id'] =customer['Cust_id'].str.replace("Cust_",'')
Redox
  • 9,321
  • 5
  • 9
  • 26