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 7836387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:07:19+00:00 2026-06-02T14:07:19+00:00

I grabbed the KDD track1 dataset from Kaggle and decided to load a ~2.5GB

  • 0

I grabbed the KDD track1 dataset from Kaggle and decided to load a ~2.5GB 3-column CSV file into memory, on my 16GB high-memory EC2 instance:

data = np.loadtxt('rec_log_train.txt')

the python session ate up all my memory (100%), and then got killed.

I then read the same file using R (via read.table) and it used less than 5GB of ram, which collapsed to less than 2GB after I called the garbage collector.

My question is why did this fail under numpy, and what’s the proper way of reading a file into memory. Yes I can use generators and avoid the problem, but that’s not the goal.

  • 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-06-02T14:07:22+00:00Added an answer on June 2, 2026 at 2:07 pm
    import pandas, re, numpy as np
    
    def load_file(filename, num_cols, delimiter='\t'):
        data = None
        try:
            data = np.load(filename + '.npy')
        except:
            splitter = re.compile(delimiter)
    
            def items(infile):
                for line in infile:
                    for item in splitter.split(line):
                        yield item
    
            with open(filename, 'r') as infile:
                data = np.fromiter(items(infile), float64, -1)
                data = data.reshape((-1, num_cols))
                np.save(filename, data)
    
        return pandas.DataFrame(data)
    

    This reads in the 2.5GB file, and serializes the output matrix. The input file is read in “lazily”, so no intermediate data-structures are built and minimal memory is used. The initial load takes a long time, but each subsequent load (of the serialized file) is fast. Please let me if you have tips!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've grabbed some Scala CSV parsing code from here: Use Scala parser combinator to
Is it possible to turn a paragraph of text (grabbed from a textbox) into
I have a JavaScript variable I grabbed from a form field and I am
I'm working on a long string grabbed from a Session that uses § (Section
I grabbed this from the book I'm learning from. public void run() { //
I've just grabbed the tip of Andengine GLES2 from github. When I bring the
I just grabbed vs2010 release from msdn and I wanted to find out if
The following code was grabbed from MSDN: http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.stringlengthattribute.aspx [MetadataType(typeof(ProductMetadata))] public partial class Product {
I need to change what rows are grabbed from the database based upon a
I'm trying to parse the json grabbed from here . Basically what I do

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.