0

I have an excel spread sheet of data for which i am opening in python. The spreadsheet has a heading and all the data values in each column, e.g.

Time
00:07
00:15
...

I have opened the file and split it into columns (each with a heading and the data below):

for line in open ('name_of_file'):
    column = line.split(',')
    time = column[0].split(',')
    print(time[0])

this prints out a list such as:

Time
00
01
02

I was wondering whether there is a way of removing the first entry in these printed columns?

Remi Guan
  • 21,506
  • 17
  • 64
  • 87
Damo
  • 3
  • 1
  • The two time lists (in the question above) are in columns – Damo Oct 20 '15 at 04:26
  • FOR THE LOVE OF ALL THAT IS HOLY, DO NOT REIMPLEMENT CSV PARSING BY HAND! WE HAVE [A MODULE FOR THAT](https://docs.python.org/3/library/csv.html)! ... Sorry, got a little carried away there. – ShadowRanger Oct 20 '15 at 04:30
  • Also, you are splitting a line by `,`, then expecting that any of the resulting values will contain `,`. That's not going to happen (unless you're using `csv` to parse and a column contains quoted commas or somesuch). You'd need to provide sample input data to work with here. – ShadowRanger Oct 20 '15 at 04:31
  • Possible duplicate of [Remove leading 0's for str(date)](http://stackoverflow.com/questions/7618863/remove-leading-0s-for-strdate) – tripleee Oct 20 '15 at 04:59
  • Thank you all, that makes it a lot easier. – Damo Oct 20 '15 at 10:36

1 Answers1

0

You can use the csv module to help you along, and then skip the first line:

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
Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284