Read a text file into a pandas dataframe or numpy array
<p>I have a file that looks like this - <a href="http://pastebin.com/u1A7v1CV" rel="nofollow">http://pastebin.com/u1A7v1CV</a></p>

<p>It's just a sample of two rows from a file. 
The rows contain <code>word_label_id</code> followed by <code>freq</code>. 
For example, <code>word_label_id</code> 1237 occurs 1 time in the first row, 1390 occurs 1 time and so on...</p>

<p>I need to use this sparse representation but I'm unable to convert it into a <code>DataFrame</code> or any other usable format. </p>

<p>Edit: I know that pandas has a <code>read_csv</code> method where I can use a space as the delimiter. This is not ideal as I need two separators - one between <code>word_label_id</code> and <code>freq</code> and a different separator between this pair and the next. </p>

<p>Here's what I did.
This creates a dictionary containing key-value pairs 
from each row. </p>

<pre><code>data = []

with open('../data/input.mat', 'r') as file:
    for i, line in enumerate(file):
        l = line.split()
        d = dict([(k, v) for k, v in zip(l[::2], l[1::2])])
        data.append(d)
</code></pre>

python numpy text dataframe