0

I have a following columns in pandas dataframe which has postal code column -

postal code    city     country
56789-2345     Dallas    USA
45675          Austin    USA
null           Houston   USA
23445-445      Dallas    USA
1234-45        Austin    USA
34567          Houston   USA

I need to break postal code into postal code and ext like below. Like separate the string from hyphen(-) -

postal_code     postal_ext    city      country
56789           2345          Dallas     USA
45675                         Austin     USA
null                          Houston    USA
23445           445           Dallas     USA
1234            45            Austin     USA
34567                         Houston    USA

How can i do this

Codegator
  • 459
  • 7
  • 28

1 Answers1

1

This is join

out = df.pop('postal code').str.split('-',expand=True)
out.columns = ['Postal code','postal_ext']
out = out.join(df)
BENY
  • 317,841
  • 20
  • 164
  • 234