地理位置的提取与分离

2024-04-20 11:17:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这样的字符串列表:

["Ola, Uber's India rival, invests $100M in scooter rental startup Vogo","Chattanooga startup Bellhops Moving raises over $31 million in latest", "Boston biotech Entrada launches with $59M to tackle deadly disease"]

我想从字符串列表中识别像印度、波士顿、查塔努加这样的字符串,这些字符串是城市、城镇、国家、州或大陆,并根据地区将它们分开。你知道吗

我无法找到一个正确的路径或方法来实现这个特定的输出。任何建议都会很有帮助。你知道吗


Tags: 字符串in列表movinguberstartupindiarental
2条回答

要探测国家和城市,可以使用geotext:https://pypi.org/project/geotext/

您需要使用GeoText库。您可以通过在windows的命令提示符cmd中键入以下命令来安装它。你知道吗

pip install https://github.com/elyase/geotext/archive/master.zip

一旦安装,您可以提取城市和国家。你知道吗

from geotext import GeoText
your_list=["Ola, Uber's India rival, invests $100M in scooter rental startup Vogo","Chattanooga startup Bellhops Moving raises over $31 million in latest", "Boston biotech Entrada launches with $59M to tackle deadly disease"]
complete_string=','.join(map(str,your_list) ) # converting the list 'your_list' to string
locations=GeoText(complete_string)
locations.countries
    ['India']
locations.cities
    ['Chattanooga', 'Boston']

相关问题 更多 >