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>Ok, it's not ideal but you can use notepad++.</p>

<p>It had a "find and replace" feature and you can use \t to replace tabs as \n</p>

<p>Then you can record a macro to move any given line to the previous, skipping lines.</p>

<p>Then you can use pandas, pd.from_csv but you have to define delimiters as tabs instead of commas </p>

<p>Another option is to read each line,and process it separately.  Basically a while loop with the condition being not m_line == null</p>

<p>Then inside the loop, split the string up with str.split ()</p>

<p>And have another loop that makes a dictionary, for each row.  In the end, you'd have a list of dictionaries where each entry is ID:frequency</p>

python numpy text dataframe