从tuple到整数使用csv文件 [英] from tuple to integer using csv files

查看:188
本文介绍了从tuple到整数使用csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用csv.reader有一个小问题。

I'm having a little problem using csv.reader.

我有两个文件:

FileA对应于9个地理坐标(x(column1)和y(column2),没有标题)。该文件从excel保存到csv文件。

FileA corresponds to 9 geographical coordinates (x (column1) and y(column2), with no headers). The file is save from excel into a csv file.

301506  5918202
301012  5919417
309769  5919926
299337  5924043
299602  5924730
305310  5907794
300634  5927108
303968  5922319
303684  5922062
304882  5922009

FileB是一个从0到8之间的9个整数的随机序列。文件保存为excel中的csv文件。数据在第1行。

FileB which is a random sequence of 9 integers between 0 and 8. The file is save as an csv file from excel. The data are in row 1.

6     3     7     8     5     1     2     4     0

这里是代码:

import csv

FileA = csv.reader(open(‘FileA.csv’,'rb'),delimeter=',')
coord_list = []
coord_list.extend(FileA)
coordinates = []
for data in coord_list:
     coordinates.append(data[0])
print coordinates

FileB = csv.reader(open(‘FileB.csv’,'rb'),delimeter=',')
seq_list = []
seq_list.extend(FileB)
sequence = []
for data in seq_list:
    sequence.append(data[0])
print sequence


FileC = []

for i range(0,8,1):
         FileC[sequence[i], 1] = coordinates[i,1]
         FileC[sequence[i], 2] = coordinates[i,2]

print FileC

但我得到:

File "C:\generatesequence\script.py", line 19, in <module>
    FileC[sequence[i], 1] = coordinates[i,1]
TypeError: list indices must be integers, not tuple

我想构建FileC以便在ArcMAP中使用它。

I want to build the FileC to be able to use it after in ArcMAP

欢迎任何建议: / p>

Any advice is welcome :)

推荐答案

a [b,c] indexes a (b,c)。你需要仔细思考你在这样做的具体行上想做什么。

a[b, c] indexes a with the tuple (b, c). You need to think hard about what you really want to do at the specific lines where you do this.

这篇关于从tuple到整数使用csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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