<div dir="ltr">Thomas,<div><br></div><div>Unless I'm misunderstanding, I think Peng Yu doesn't want to read the zeros (or empty values) from the tsv file into memory. I'm pretty sure pandas.read_csv reads your whole data into memory, zeros or not. There is no option to read it in a sparse format (only store the position of nonzero entries). So that doesn't solve the problem. </div><div><br></div><div>I think you can also read it in chunks, call df.to_sparse to convert to a sparse matrix for each chunk and concat them. I'm not sure if you've seen this: <a href="https://stackoverflow.com/questions/31888856/read-a-large-csv-into-a-sparse-pandas-dataframe-in-a-memory-efficient-way">https://stackoverflow.com/questions/31888856/read-a-large-csv-into-a-sparse-pandas-dataframe-in-a-memory-efficient-way</a>, but it might also offer some useful insights.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jan 29, 2020 at 5:57 PM Thomas Kluyver <<a href="mailto:takowl@gmail.com">takowl@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 29 Jan 2020 at 09:34, Peng Yu <<a href="mailto:pengyu.ut@gmail.com" target="_blank">pengyu.ut@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Where it documented that pandas.read_csv don't generate the whole<br>
matrix? The return value is either of the two?<br></blockquote><div><br></div><div>It returns a 2D data structure as in the rows and columns of your CSV file - so the shape will be (3, n_entries). It doesn't try to interpret them as referring to entries in a matrix - you have to do that as a separate step.</div><div><br></div><div>It's probably not exactly documented like this, because documentation doesn't usually say what a function *doesn't* do, unless it's a very common confusion.</div><div><br></div><div>Thomas<br></div></div></div>
_______________________________________________<br>
SciPy-User mailing list<br>
<a href="mailto:SciPy-User@python.org" target="_blank">SciPy-User@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/scipy-user" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/scipy-user</a><br>
</blockquote></div>