2

i have a Ubuntu laptop with 8 GB ram .and also have a 2 GB CSV file but when i use pandas method read_csv to load my data the ram is completely filled while there was 7 GB ram free . how does 2 GB file fill 7 GB ram ?

2

2 Answers 2

3

The reason you get this low_memory warning might be because guessing dtypes for each column is very memory demanding. Pandas tries to determine what dtype to set by analyzing the data in each column.

In case using 32-bit system : Memory errors happens a lot with python when using the 32bit version in Windows. This is because 32bit processes only gets 2GB of memory to play with by default.

Try this :

tp = pd.read_csv('file_name.csv', header=None, chunksize=1000)
df = pd.concat(tp, ignore_index=True)
Sign up to request clarification or add additional context in comments.

2 Comments

yes .it was because of dtypes , and i converted some columns dtype as i was loading . thanks.
i have tried to upvote , but it is not displayed publicly because i have less than 15 reputation ;)
0

try to make use of chunksize parameter:

df = pd.concat((chunk for chunk in pd.read_csv('/path/to/file.csv', chunksize=10**4)),
               ignore_index=True)

2 Comments

your first is horribly inefficient add the note: pandas.pydata.org/pandas-docs/stable/merging.html
every loop iteration you were making a copy of a bigger and bigger frame; instead append to a list and call concat once (as the current example does)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.