作为练习,我想测试一些东西。我有一个在线的巨大CSV文件https://raw.github.com/datasets/gdp/master/data/gdp.csv ,我想读取所有数据并将其放入表格中,以便分析和制作表格。 到目前为止,我所拥有的代码是使用其他StackOverflow问题和其他网站组合而成。但是当它被读取并立即再次打印时,结果是逐字逐句地输出,因此我得到:
['C']
['o']
['u']
['n']
['t']
['r']
['y']
[' ']
['N']
['a']
['m']
['e']
['', '']
['C']
['o']
['u']
['n']
['t']
['r']
['y']
[' ']
['C']
['o']
['d']
['e']
['', '']
['Y']
['e']
['a']
['r']
['', '']
['V']
['a']
['l']
['u']
['e']
[]
[]
['A']
['r']
['a']
['b']
[' ']
['W']
['o']
['r']
['l']
['d']
['', '']
我目前的代码如下:
import csv
import urllib.request
url = "https://raw.github.com/datasets/gdp/master/data/gdp.csv"
webpage = urllib.request.urlopen(url)
datareader = csv.reader(webpage.read().decode('utf-8'))
data = []
for row in datareader:
data.append(row)
for row in data:
print(row)
如何更改代码使其逐行读取并将每一行拆分为不同的变量。以前我用过以下代码:
payRollNumber, salary, jobTitle, otherNames, \
surname = line.strip().split(',')
我得到行后可以应用这个。有什么想法吗?