Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
删除数据列中的条目,python_Python - Fatal编程技术网

删除数据列中的条目,python

删除数据列中的条目,python,python,Python,我有一个excel数据电子表格,我正在用python打开它。电子表格有一个标题和每列中的所有数据值,例如 Time 00:07 00:15 ... 我已打开文件并将其拆分为列(每个列都有标题和以下数据): 这将打印出一个列表,例如: Time 00 01 02 我想知道是否有办法删除这些打印列中的第一个条目?您可以使用csv模块帮助您,然后跳过第一行: import csv with open('name_of_file') as f: reader = csv.reader(f)

我有一个excel数据电子表格,我正在用python打开它。电子表格有一个标题和每列中的所有数据值,例如

Time
00:07
00:15
...
我已打开文件并将其拆分为列(每个列都有标题和以下数据):

这将打印出一个列表,例如:

Time
00
01
02

我想知道是否有办法删除这些打印列中的第一个条目?

您可以使用
csv
模块帮助您,然后跳过第一行:

import csv

with open('name_of_file') as f:
    reader = csv.reader(f)
    next(reader) # skips the first line, the header
    for row in reader:
       print(row[0]) # The first column

这两个时间列表(在上面的问题中)列在列中,为了爱所有神圣的事物,不要手工重新实现!我们有。。。很抱歉,这里有点失控。另外,您正在将一行拆分为
,然后期望任何结果值都包含
。这是不会发生的(除非您使用
csv
进行解析,并且一列包含带引号的逗号或诸如此类的内容)。您需要提供示例输入数据,以便在此处使用。可能与“谢谢大家”重复,这会使操作更轻松。
import csv

with open('name_of_file') as f:
    reader = csv.reader(f)
    next(reader) # skips the first line, the header
    for row in reader:
       print(row[0]) # The first column