How to split strings inside a numpy array?

Viewed 16478

I have the following table:

As the column 'location' has the state repeating inside it, I am trying to remove the state from location so that it only has the city name.

year    location    state   success
2009    New York, NY    NY  1
2009    New York, NY    NY  1
2009    Chicago, IL IL  1
2009    New York, NY    NY  1
2009    Boston, MA  MA  1
2009    Long Beach, CA  CA  1
2009    Atlanta, GA GA  1

I have tried the following code:

x = KS_clean.column(1)
np.chararray.split(x, ',')

How can I split the string so the result only contains the city name like the following:

array('New York', 'New York', 'Chicago', ...,) 

so that I can put it back inside the table?

Sorry it is basic question but I am new to python and still learning. Thanks

1 Answers
Related