Created
May 25, 2021 09:49
-
-
Save ericgitonga/c1b0597b0d02047be365be07f3768c77 to your computer and use it in GitHub Desktop.
Code to properly fill city column
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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