从此代码创建坐标对 [英] Create a coordinate pair from this code

查看:58
本文介绍了从此代码创建坐标对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我当前的代码

a_reader = None
a_reader     = open('data.csv', 'rU')
a_csv_reader = csv.reader(a_reader)

for row in a_csv_reader:
       print row
a_reader.close()

count = 0
sum   = 0.0
a_reader     = open('data.csv', 'rU')
a_csv_reader = csv.reader(a_reader)
a_csv_reader.next()

for row in a_csv_reader:
        if count != 0 and row[0] != '':
            sum = sum + float(row[0])
        count = count + 1

a_reader.close()
print 'Number of lines is:',count
print 'Sum is:',sum
return listStation

这将产生以下结果

['1', '476050', '7709929']    
['2', '473971', '7707713']    
['3', '465676', '7691097']    
['4', '515612', '7702192']    
['5', '516655', '7704405']    
['6', '519788', '7713255']    
['7', '538466', '7683341']    
Number of lines is: 8    
Sum is: 28.0

好的,所以我想要的输出显示在下面的双重列表中.

Ok so the output that I want is shown below in a double list.

[[476050, 7709929],[473971, 7707713],[465676, 7691097],[515612, 7702192],[516655, 7704405],[519788, 7713255],[538466, 7683341]]

如何更改代码以将结果生成为双重列表,如上所示.是否可以创建一个坐标对的双重列表,如上所示.你能帮我吗?

How can I alter my code to produce the result as a double list as shown above. Is it possible to create a doublelist of coordinate pairs as shown above. Can you help me?

感谢您的帮助.

推荐答案

切掉最后两个元素,然后追加.

Slice off the last two elements, then append.

>>> ['1', '476050', '7709929'][1:3]
['476050', '7709929']

这篇关于从此代码创建坐标对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆