[英]Python CSV reader prints column instead of row
I have a dataset that i saved as a csv in Sublime after pasting from excel 从Excel粘贴后,我有一个数据集我保存为Sublime中的csv
When I call csv.reader to print all the rows, the whole set is printed out (fantastic): 当我调用csv.reader来打印所有行时,整套打印出来了(很棒):
Output 1 输出1
Now that I want to call to print the first row of my dataset "print(row[0])", the first entire column of my dataset prints out: 现在我要调用以打印我的数据集“ print(row [0])”的第一行,我的数据集的第一整列将打印出来:
Output 2 输出2
PLEASE HELP! 请帮忙! I am trying to learn python.
我正在尝试学习python。
row
is a row. row
是一行。 row[0]
is the first element of that row. row[0]
是该行的第一个元素。
If you want to just print the first row, do print(row)
then break
to stop the iteration. 如果您只想打印第一行,请执行
print(row)
然后break
以停止迭代。
You have to use such code: 您必须使用以下代码:
import csv
with open("exampleSet.csv") as productivityCost:
readPC = csv.reader(productivityCost, delimeter = ",")
print(row[0])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.