Skip to content

Instantly share code, notes, and snippets.

@ericgitonga
Created May 25, 2021 09:49
Show Gist options
  • Save ericgitonga/c1b0597b0d02047be365be07f3768c77 to your computer and use it in GitHub Desktop.
Save ericgitonga/c1b0597b0d02047be365be07f3768c77 to your computer and use it in GitHub Desktop.
Code to properly fill city column
for i in df.index:
if len(df.loc[i, 'Location'].split(', ')) == 3:
df.loc[i, 'City'] = df.loc[i, 'Location'].split(', ')[1]
elif len(df.loc[i, 'Location'].split(', ')) == 2:
df.loc[i, 'City'] = df.loc[i, 'Location'].split(', ')[0]
else:
df.loc[i, 'City'] = np.nan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment