Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 860757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:51:57+00:00 2026-05-15T08:51:57+00:00

I am trying to read a very simple but somehow large(800Mb) csv file using

  • 0

I am trying to read a very simple but somehow large(800Mb) csv file using the csv library in python. The delimiter is a single tab and each line consists of some numbers.
Each line is a record, and I have 20681 rows in my file. I had some problems during my calculations using this file,it always stops at a certain row. I got suspicious about the number of rows in the file.I used the code below to count the number of row in this file:

tfdf_Reader = csv.reader(open('v2-host_tfdf_en.txt'),delimiter=' ')
c = 0
for row in tfdf_Reader:
  c = c + 1
print c

To my surprise c is printed with the value of 61722!!! Why is this happening? What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:51:58+00:00Added an answer on May 15, 2026 at 8:51 am

    800 million bytes in the file and 20681 rows means that the average row size is over 38 THOUSAND bytes. Are you sure? How many numbers do you expect in each line? How do you know that you have 20681 rows? That the file is 800 Mb?

    61722 rows is almost exactly 3 times 20681 — is the number 3 of any significance e.g. 3 logical sub-sections of each record?

    To find out what you really have in your file, don’t rely on what it looks like. Python’s repr() function is your friend.

    Are you on Windows? Even if not, always open(filename, 'rb').

    If the fields are tab-separated, then don’t put delimeter=" " (whatever is between the quotes appears not to be a tab). Put delimiter="\t".

    Try putting some debug statements in your code, like this:

    DEBUG = True
    f = open('v2-host_tfdf_en.txt', 'rb')
    if DEBUG:
        rawdata = f.read(200)
        f.seek(0)
        print 'rawdata', repr(rawdata)
        # what is the delimiter between fields? between rows?
    tfdf_Reader = csv.reader(f,delimiter=' ')
    c = 0
    for row in tfdf_Reader:
        c = c + 1
        if DEBUG and c <= 10:
            print "row", c, repr(row)
            # Are you getting rows like you expect?
    print "rowcount", c
    

    Note: if you are getting Error: field larger than field limit (131072), that means your file has 128Kb of data with no delimiters.

    I’d suspect that:

    (a) your file has random junk or a big chunk of binary zeroes apppended to it — this should be obvious in a hex editor; it also should be obvious in a TEXT editor. Print all the rows that you do get to help identify where the trouble starts.

    or (b) the delimiter is a string of one or more whitespace characters (space, tab), the first few rows have tabs, and the remaining rows have spaces. If so, this should be obvious in a hex editor (or in Notepad++, especially if you do View/Show Symbol/Show all characters). If this is the case, you can’t use csv, you’d need something simple like:

    f = open('v2-host_tfdf_en.txt', 'r') # NOT 'rb'
    rows = [line.split() for line in f]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.