2015-02-07 4 views
0

두 개의 헤더를 쓰고 싶지만 실제 두 개의 헤더와 세 개의 빈 필드를 수신하고 있습니다. 이것의 원인이 무엇일까요? 여기 내 스크립트 및 출력입니다. 이 스크립트는 JSON 웹 서비스를 구문 분석하고 버스의 lat/lng를 Esri 파일 지오 데이터베이스에 보냅니다.Python CSV 헤더가 올바르게 쓰여지지 않습니다.

enter image description here

enter image description here

import requests 
import json 
import urllib2 
import csv 
import arcpy 





if arcpy.Exists("C:\MYLATesting.gdb\API_Table"): 
    arcpy.Delete_management("C:\MYLATesting.gdb\API_Table") 

url = "http://api.metro.net/agencies/lametro/vehicles/" 
parsed_json = json.load(urllib2.urlopen("http://api.metro.net/agencies/lametro/vehicles/")) 
details = {'items': 'longitude'} 
headers = {'Content-type': 'application/x-www-form-urlencoded', 'Accept': '/'} 
response = requests.get(url, data=json.dumps(details), headers=headers) 


# tell computer where to put CSV 
outfile_path='C:\Users\Administrator\Desktop\API_Testing.csv' 

# open it up, the w means we will write to it 
writer = csv.writer(open(outfile_path, 'wb')) 

#create a list with headings for our columns 
headers = ['latitude','longitude'] 

for items in parsed_json['items']: 
    row = [] 
    row.append(str(items['latitude']).encode('utf-8')) 
    row.append(str(items['longitude']).encode('utf-8')) 
    writer.writerow(row) 

i = 1 
i = i +1 

f = open(outfile_path, 'wb') 
writer = csv.writer(f) 
#write the row of headings to our CSV file 
writer.writerow(headers) 

f.close() 

#Temporary Delete Function to Overwrite Table 

arcpy.TableToTable_conversion(outfile_path, "C:\MYLATesting.gdb", "API_Table") 

print response.text 

답변

0

여분의 빈 열이 두 가지 중 하나를 의미 할 수있다 : 1.있는 거 스크립트 추가 쉼표를 출력 (,)로 각 줄의 끝에서하는 스프레드 시트 프로그램은 추가 열 또는 을 해석합니다. 2. TableToTable_conversion 함수는 데이터베이스 스키마처럼 보이는 것을 수행합니다.

데이터베이스 스위트를 통해 CVS를보고 있습니까? 메모장에서 보이는 모양의 스크린 샷을 게시하십시오.

+0

저는 함수가 CSV에서 필드를 취하는 것처럼 내 TabletoTable_Conversion이라고 생각하지 않습니다. –

관련 문제