0

enter image description here

df['business location'] #column i want to split into 2 columns : 
df['longitude'] #and
df['latitude']

df[['longitude','latitude']] = sf['Business Location'].str.split(',')

is giving me error: ValueError: Must have equal len keys and value when setting with an iterable

how do I split?

Umar.H
  • 22,559
  • 7
  • 39
  • 74
Sweta
  • 1
  • 1
  • 2
    try using `expand=True` i.e `df.join(df['Business Location'].str.split(',',expand=True).rename(columns={0 : 'long', 1 : 'lat'}))` – Umar.H Nov 17 '20 at 13:49
  • 1
    agree with the dupe make sure you look at the highest rated answer not the accepted one. – Umar.H Nov 17 '20 at 13:51

1 Answers1

-1

This will work

df.assign(
      longitude=lambda x: x['Business Location'].str.split(',').str[0],
      latitude=lambda x: x['Business Location'].str.split(',').str[1])
Rik Kraan
  • 586
  • 2
  • 16