title: convert .dat into .csv in python
body: <p>I want to convert a data set of an <code>.dat</code> file into <code>csv</code> file. The data format looks like,</p>
  
  <p><code>Each row begins with the sentiment score followed by the text associated with that rating.</code></p>
  
  <p><img src="https://i.stack.imgur.com/npxmc.png" alt="Image of the .dat file"></p>
  
  <p>I want the have sentiment value of (-1 or 1) to have a column and the text of review corresponding to the sentiment value to have an review to have an column.</p>
  
  <p>WHAT I TRIED SO FAR</p>
  
  <pre><code>import pandas as pd
  import seaborn as sns
  import matplotlib.pyplot as plt
  import numpy as np  
  import csv
  
  # read flash.dat to a list of lists
  datContent = [i.strip().split() for i in open("train.dat").readlines()]
  
  # write it as a new CSV file
  with open("train.csv", "wb") as f:
      writer = csv.writer(f)
      writer.writerows(datContent)
  def your_func(row):
      return row['Sentiments'] / row['Review']
  
  columns_to_keep = ['Sentiments', 'Review']
  dataframe = pd.read_csv("train.csv", usecols=columns_to_keep)
  dataframe['new_column'] = dataframe.apply(your_func, axis=1)
  
  print dataframe
  </code></pre>
  
  <p>Sample screen shot of the resulting train.csv it has an comma after every word in the review.</p>
  
  <p><img src="https://i.stack.imgur.com/FGxv1.png" alt="Output of the train.csv"></p>