0

I have a data-frame:

df1 = pd.DataFrame({'ShipTo': ["", "", "", ""], 'Item_Description':["SYD_QANTAS ", "SYD_QANTAS", "PVG_SHANGHAI", "HKG_JARDINE"]})

I'd like to create a string merge in the column ShipTo "B" + first 3 characters from the column "Item_Description" so the result would be:

enter image description here

How can I do that?

0

1 Answer 1

1

TRy this,

df["ShipTo"] = "B"+df1['Item_Description'].str[:3]

O/P:

  ShipTo Item_Description
0   BSYD      SYD_QANTAS 
1   BSYD       SYD_QANTAS
2   BPVG     PVG_SHANGHAI
3   BHKG      HKG_JARDINE

Slice first 3 elemnts of Item Description column and merge with your string literal.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.