2016-11-07 110 views
0

這裏是我的代碼,我嘗試運行,但我沒有在輸出端獲得的值,爲什麼返回值只有南?

import numpy 
import geocoder 

data = numpy.loadtxt(fname = 'Flywheel_SF.csv', delimiter = ',', dtype = numpy.ndarray) 
start = list() 
end = list() 
z_code = numpy.zeros((101,2)) 

for i in range(1,101): 
    s = geocoder.google([data[i,4], data[i,5]], method='reverse') 
    e = geocoder.google([data[i,6], data[i,7]], method='reverse') 
    start.append(s.postal) 
    end.append(e.postal) 
    z_code[i,0] = s.postal 
    z_code[i,1] = e.postal 


zipcode = [start, end] 

print(z_code) 

這裏是我得到的輸出,

[[ 0. 0.] 
[ nan nan] 
[ nan nan] 
[ nan nan] 
[ nan nan] 
.... 
.... 
[ nan nan] 
[ nan nan] 
[ nan nan] 
[ nan nan] 
[ nan nan] 
[ nan nan]] 

輸出應該是這樣的,這些是從經度和經度轉換的郵編

[[  0.  0.] 
[ 94105. 94103.] 
[ 94133. 94108.] 
[ 94133. 94133.] 
[ 94114. 94122.] 
[ 94104. 94128.] 
[ 94128. 94066.] 
...... 
...... 
[ 94128. 94066.] 
[ 94118. 94116.] 
[ 94109. 94102.]] 

請幫助,提前謝謝!

+0

你檢查,當你閱讀s.postal從地理編碼器返回的數據類型? 「 –

+0

」numpy.loadtxt([...],dtype = numpy.ndarray)「我想知道你是否理解dtype的使用,嘗試刪除它。 「因爲我在範圍(1,101)」索引從Numpy開始。如果您嘗試跳過Flywheel_SF.csv中的標題行,最好使用numpy.loadtxt的「skiprows」選項。 – Balzola

回答