Parsing an irregularly spaced text file in Python pandas
<p>I have a text file that looks like :</p>

<pre><code>Date     Fruit-type  Color         count
aug-6     apple  green         4
aug-7     pear  brown         5
aug-3     peach  yellow         10
aug-29     orange  orange         34
</code></pre>

<p>I would like to parse it to remove the irregular spaces into a nicely formatted pandas dataframe. I thought to remove the spaces and replace them with another delimiter but could not figure out the logic.</p>

<p>Desired output</p>

<pre><code>Date,Fruit-type,Color,count
aug-6,apple,green,4
aug-7,pear,brown,5
aug-3,peach,yellow,10
aug-29,orange,orange,34
</code></pre>

<pre><code>gawk '{gsub(/[[:blank:]]+/, ",")}1' file

Date,Fruit-type,Color,count
aug-6,apple,green,4
aug-7,pear,brown,5
aug-3,peach,yellow,10
aug-29,orange,orange,34
</code></pre>

python pandas