<p>IIUC,您希望使用数据帧中的其他值来填充缺少的值。你可以用<code>map</code>来做这件事。你知道吗</p>
<p>首先,生成一系列映射到自治区的邮政编码。你知道吗</p>
<pre><code>mapping = (df.query('Borough != "Unspecified"')
.drop_duplicates('Incident Zip')
.set_index('Incident Zip')
.Borough)
mapping
Incident Zip
11374 QUEENS
11420 QUEENS
10467 BRONX
11230 MANHATTAN
10028 MANHATTAN
11385 QUEENS
Name: Borough, dtype: object
</code></pre>
<p>现在,将其传递给<code>map</code>,并使用<code>fillna</code>将未映射的值填充为“Unspecified”。你知道吗</p>
<pre><code>df['Borough'] = df['Incident Zip'].map(mapping).fillna('Unspecified')
df
Created Date Complaint Type Incident Zip Borough
0 09/14/2017 04:40:33 PM New Tree Request 11374 QUEENS
1 03/18/2017 10:09:57 AM General Construc 11420 QUEENS
2 03/29/2017 12:38:28 PM General Construc 11230 MANHATTAN
3 06/05/2017 12:47:55 PM New Tree Request 10028 MANHATTAN
4 06/15/2017 11:56:36 AM Dead/Dying Tree 10467 BRONX
5 06/19/2017 10:30:46 AM New Tree Request 11230 MANHATTAN
6 06/29/2017 09:25:59 AM New Tree Request 10028 MANHATTAN
7 07/01/2017 12:23:20 PM Damaged Tree 10467 BRONX
8 07/01/2017 11:47:03 AM Damaged Tree 10467 BRONX
9 07/10/2017 10:27:37 AM General Construc 11385 QUEENS
</code></pre>