Python Forum
Load specific set of Rows CSV
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Load specific set of Rows CSV
#5
it's late in the evening for Larz and maybe he is tired so he suggest something that will raise exception

import csv
 
with open('File.csv') as fp:
    reader = csv.reader(fp)
    fields = None # no need of this
    fields = [field for field in reader] # you will read the whole file here
    # process fields here
    next(reader) # this will rise an exception because reader is exhausted - you are at the end of the file
better
import csv
 
with open('File.csv') as fp:
    reader = csv.reader(fp)
    for line in reader: # iterate over lines in the file
        # process line here
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
Load specific set of Rows CSV - by Marcuslang - Jun-30-2018, 07:18 PM
RE: Load specific set of Rows CSV - by Larz60+ - Jun-30-2018, 10:14 PM
RE: Load specific set of Rows CSV - by Marcuslang - Jul-01-2018, 07:22 AM
RE: Load specific set of Rows CSV - by Larz60+ - Jul-01-2018, 07:35 AM
RE: Load specific set of Rows CSV - by buran - Jul-01-2018, 07:52 AM
RE: Load specific set of Rows CSV - by Larz60+ - Jul-01-2018, 01:58 PM
RE: Load specific set of Rows CSV - by Marcuslang - Jul-01-2018, 05:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Write specific rows from pandas dataframe to csv file pradeepkumarbe 3 5,608 Oct-18-2018, 09:33 PM
Last Post: volcano63
  Removing rows at random based on the value of a specific column Mr_Keystrokes 4 5,723 Aug-24-2018, 11:15 AM
Last Post: Mr_Keystrokes
  How to filter specific rows from large data file Ariane 7 8,326 Jun-29-2018, 02:43 PM
Last Post: gontajones

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020