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>Have you tried work separately with each item?</p>

<p>For example:</p>

<p>Open document:</p>

<pre><code>with open('delimiters.txt') as r:
    lines = r.readlines()
    linecontent = ' '.join(lines)
</code></pre>

<p>Create a list for each item:</p>

<pre><code>result = linecontent.replace(' ', ',').split(',')
</code></pre>

<p>Create sublist for ids and freqs:</p>

<pre><code>newResult = [result[x:x+2] for x in range(0, len(result), 2)]
</code></pre>

<p>Working with each data type:</p>

<pre><code>ids = [x[0][:] for x in newResult]
freq = [x[1][:] for x in newResult]
</code></pre>

<p>Create a DataFrame</p>

<pre><code>df = pandas.DataFrame({'A ids': ids, 'B freq': freq})
</code></pre>

<p><a href="http://i.stack.imgur.com/e7kOt.png" rel="nofollow"><img src="http://i.stack.imgur.com/e7kOt.png" alt="enter image description here"></a></p>

python numpy text dataframe