Python 如何在数据集中填充缺失的地理位置?
我有一组数据集,同时缺少地理位置名称和坐标。我想填补这些空白,以便我可以继续进行未来的数据分析。数据集是从twitter上收集的,因此它不是一个创建的数据,但数据就是这样来的,我需要以某种方式填补空白,并继续进行未来的分析 选项1:我可以使用Python 如何在数据集中填充缺失的地理位置?,python,pandas,geolocation,geopy,geopandas,Python,Pandas,Geolocation,Geopy,Geopandas,我有一组数据集,同时缺少地理位置名称和坐标。我想填补这些空白,以便我可以继续进行未来的数据分析。数据集是从twitter上收集的,因此它不是一个创建的数据,但数据就是这样来的,我需要以某种方式填补空白,并继续进行未来的分析 选项1:我可以使用userLocation和userTimezone来查找坐标 输入: userLocation, userTimezone, Coordinates, India, Hawaii, {u'type': u'Point', u'
userLocation
和userTimezone
来查找坐标
输入:
userLocation, userTimezone, Coordinates,
India, Hawaii, {u'type': u'Point', u'coordinates': [73.8567, 18.5203]}
California, USA
, New Delhi,
Ft. Sam Houston,Mountain Time (US & Canada),{u'type': u'Point', u'coordinates': [86.99643, 23.68088]}
Kathmandu,Nepal, Kathmandu, {u'type': u'Point', u'coordinates': [85.3248024, 27.69765658]}
预期产量
userLocation, userTimezone, Coordinates_one, Coordinates_two
India, Hawaii, 73.8567, 18.5203
California, USA, [fill this] [fill this]
[Fill this], New Delhi, [fill this] [fill this]
Ft. Sam Houston,Mountain Time (US & Canada), 86.99643, 23.68088
Kathmandu, Kathmandu, 85.3248024, 27.69765658
是否可以用Python或pandas编写脚本,在正确设置输出格式的同时填充缺少的位置名称和坐标
我知道Python或Pandas没有任何神奇的软件包,但从一些东西开始会很有帮助
我在第节问过这个问题,但在那里没有什么帮助。这是我第一次使用地理位置数据集,我不知道如何开始。如果问题不合适,请评论删除,而不是否决表决 正如其他人在你的问题上提到的那样,没有神奇的方法可以制作出准确的东西,但我会玩弄它。我假设您能够循环查看丢失的数据、示例代码和输出:
from geopy.geocoders import Nominatim
geolocator = Nominatim()
for location in ('California USA', 'New Delhi'):
geoloc = geolocator.geocode(location)
print location, ':', geoloc, geoloc.latitude, geoloc.longitude
输出:
California USA : California, United States of America 36.7014631 -118.7559974
New Delhi : New Delhi, New Delhi District, Delhi, India 28.6138967 77.2159562
您可能希望尝试不同的地理编码服务(请参阅),其中一些服务可以采用其他参数,例如提名可以采用“country_bias”关键字,这将使结果偏向给定的国家。我认为您必须检查和谢谢!从一开始就很好。