2013-04-19 3 views
4

좋아요는, 문제는 간단하다세이지 CSV에서 가져 오기와 숫자를 세우고보다 큰 10

나는 간단한 산포도 그리기하려고하면이 데이터에서

import csv 

a = csv.reader(open(DATA+'testi1.csv')) 

G = Graphics() 

    for col in a: 
    time = col[0] 
    conversion = col[2] 
    x_series = time 
    y_series = conversion 
    plot = scatter_plot (zip(x_series,y_series)) 
    G += plot 

G.set_axes_range(0, 20, 0, 20) 

G 

을 :

1,2,3 
2,4,6 
3,6,9 
4,8,12 
5,10,15 
6,12,18 

우리가 값을 얻을 때까지 잘 작동하는 그래프 결과 12 15 18
다음과 같이 그래프로 표시됩니다 :

1,3 
2,6 
3,9 
4,1 
5,1 
6,1 

0 나는 똑바로 값을 입력과 같은 시도 :

이 잘 작동 그래프 결과
G = Graphics() 

x_series = (1,2,3,4,5,6) 
y_series = (3,6,9,12,15,18) 
plot = scatter_plot(zip(x_series,y_series)) 
G += plot 

G.set_axes_range(0, 20, 0, 20) 

G 

, 그것은 아무런 문제없이 그려됩니다. 문제가 csv.reader라고 가정합니다.하지만 어떻게 해야할지 잘 모릅니다.

답변

1

OK, 당신이 시도 할 수 있습니다 :

이 작동
import csv 

a = csv.reader(open(DATA+'testi1.csv')) 
G = Graphics() 

# create 2 lists so as to save the desired column fields 
x_series=[] 
y_series=[] 

# iterate the csv file 
for x,y,z in a: 
    # append the first and third columns to 
    # x_series and y_series list respectively 
    x_series.append(int(x)) 
    y_series.append(int(z)) 

# then make the scatter plot 
plot = scatter_plot(zip(x_series,y_series)) 
G += plot 

G.set_axes_range(0, 20, 0, 20) 

G 
+0

, 대단히 감사합니다! –

+0

내가 도울 수있어서 기뻐! –