What I am doing seems simple, but I cannot figure it out.
I have a dataframe with data like
City State ZIP
Ames IA 50011-3617
Ankeny IA 50021
I want to split zipcodes into -and save only the first in a new data framework that has old data and only new zipcode. I tried to do the following.
data_short_zip = data
df = data['ZIP'].str.split('-').str[0]
data_short_zip.join(df)
This not only gives rise to an error, but also looks extraordinary. Is there an easy way to do this?
The output will look like
City State ZIP
Ames IA 50011
Ankeny IA 50021
source
share