2016-05-16 33 views
-2

我有一組缺少地理位置名稱和座標的數據集在同一時間。我想填補空白,以便我可以繼續對數據進行未來分析。數據集是從Twitter收集的,因此它不是一個創建的數據,但是這就是數據來了,我需要以某種方式填補空白,並繼續進行未來的分析。如何在數據集中填寫缺失的地理位置?

選項1:我可以使用的userLocationuserTimezone的找到coordinates

輸入:

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或熊貓在正確格式化輸出的同時填寫缺失的位置名稱和座標?

我知道Python或Pandas沒有任何魔術包,但是一開始就會有幫助。

我在GIS區問了這個問題,但在那裏沒有太多的幫助。這是我第一次使用地理位置數據集,我不知道如何開始。如果問題不適合,請評論刪除它而不是投票。

+1

我認爲你必須檢查[pandas fillna()](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.fillna.html) 而[使用缺失數據](http://pandas.pydata.org/pandas-docs/stable/missing_data.html) – Leo

回答

1

正如其他人提到你的GIS的問題,沒有什麼奇妙的方式來產生準確的東西,但我會玩geopy。我假設你能夠循環在你丟失的數據,示例代碼和輸出演示geopy:

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 

你可能想嘗試不同的地理編碼服務(見geopy doc),一些這些服務可以採取額外的論據,例如提名可以採用「country_bias」這個關鍵字,它會將結果偏向給定的國家。

+0

謝謝!開始的東西很棒。 –