基本上,我在两个不同的列中有纬度和经度。我得到一个新的坐标集的两个元素列表(可能是numpy数组),我想在添加它之前检查它是否重复。在
例如,我的数据:
df = pd.DataFrame([[4,8, 'wolf', 'Predator', 10],
[5,6,'cow', 'Prey', 10],
[8, 2, 'rabbit', 'Prey', 10],
[5, 3, 'rabbit', 'Prey', 10],
[3, 2, 'cow', 'Prey', 10],
[7, 5, 'rabbit', 'Prey', 10]],
columns = ['lat', 'long', 'name', 'kingdom', 'energy'])
newcoords1 = [4,4]
newcoords2 = [7,5]
是否可以编写一个if
语句来告诉我是否已经存在具有该纬度和经度的行。在伪代码中:
{{cd2>应该是 旁注: 提前谢谢你!在(newcoords1[0] in df['lat']) & (newcoords1[1] in df['long'])
不起作用,因为它独立地检查它们,但是我需要知道这个组合是否出现在一行中。在
你可以这样做:
以下行将返回找到的行数:
^{pr2}$或者使用NumPy方法:
这将显示是否至少找到一行:
说明:
相关问题 更多 >
编程相关推荐