【发布时间】:2020-05-24 12:55:04
【问题描述】:
我希望检查一个数据框列中的类别是否与另一列中的类别匹配,即拼写等是否不匹配。
我现在有两个数组表示感兴趣列中的所有唯一值,我想返回第一个较小数组中但不在第二个较大数组中的任何值,因此我可以缩小我可能需要调整/重新拼写等的类别。我相信我应该使用 for 循环来评估每个数组,但我正在努力实现。示例代码如下,谢谢:
borough_pm25 = pm25['Borough_x'].unique()
borough_pm25
array(['Barnet', 'Camden', 'Wandsworth', 'Hounslow', 'Southwark',
'Westminster', 'Kensington & Chelsea', 'Tower Hamlets',
'Islington', 'Kingston', 'Barking & Dagenham', 'Waltham Forest',
'Haringey', 'Lambeth', 'Enfield', 'Greenwich', 'Redbridge',
'Newham', 'City of London', 'Hackney', 'Richmond', 'Ealing',
'Hammersmith & Fulham', 'Lewisham', 'Sutton', 'Havering', 'Bexley',
'Bromley'], dtype=object)
borough_map = map_df['NAME'].unique()
borough_map
array(['Kingston upon Thames', 'Croydon', 'Bromley', 'Hounslow', 'Ealing',
'Havering', 'Hillingdon', 'Harrow', 'Brent', 'Barnet', 'Lambeth',
'Southwark', 'Lewisham', 'Greenwich', 'Bexley', 'Enfield',
'Waltham Forest', 'Redbridge', 'Sutton', 'Richmond upon Thames',
'Merton', 'Wandsworth', 'Hammersmith and Fulham',
'Kensington and Chelsea', 'Westminster', 'Camden', 'Tower Hamlets',
'Islington', 'Hackney', 'Haringey', 'Newham',
'Barking and Dagenham', 'City of London'], dtype=object)
【问题讨论】:
-
谢谢 Mihai,是的,这在它返回 False 的意义上是有效的,即不匹配,但是我需要返回不匹配的实际值。
标签: python python-3.x pandas list numpy