I have a df where I want to query the postalcode to match address and city.
Postalcodestring
1181
1055
8547
I'm using nomi.query_postal_code('n') for this. Hereby, when inputting the following the table is shown:
postal_code 1181
country_code NL
place_name Amstelveen
state_name Noord-Holland
state_code 7
county_name Amstelveen
county_code 362
community_name NaN
community_code NaN
latitude 52.31
longitude 4.8631
accuracy 6
Name: 0, dtype: object
I want to fill the city and country for the column 'City1' and 'Country1' to fill each row of postal code. When a postalcode is n/a, I want the row City1 and Country1 to be N/A too!
I have tried the following code:
#NL
for i, row in df.iterrows():
df.loc[i, 'City1'] = nomi.query_postal_code(df['Postalcodestring'][i])[2]
#DE
for i, row in df.iterrows():
df.loc[i,'City2'] = nomi2.query_postal_code(df['Postalcodestring'][i])[2]
#NLCountry
for i, row in df.iterrows():
df.loc[i,['Country1']] = nomi.query_postal_code(df['Postalcodestring'][i])[1]
#DECountry
for i, row in df.iterrows():
df.loc[i,'Country2'] = nomi2.query_postal_code(df['Postalcodestring'][i])[1]
However, getting the following error:
ValueError Traceback (most recent call last)
<ipython-input-80-d0d96a6ea61b> in <module>
67 #NL
68 for i, row in df.iterrows():
---> 69 df.loc[i, 'City1'] = nomi.query_postal_code(df['Postalcodestring'][i])[2]
70 #DE
71 for i, row in df.iterrows():
ValueError: DataFrame constructor not properly called!
Desired output:
Postalcodestring City1
1181 Amstelveen
1055 Amsterdam
8547 NaN
Please help !