title: reading and doing calculation from .dat file in python
body: <p>I need to read a .dat file in python which has 12 columns in total and millions of lines of rows. I need to divide column 2,3 and 4 with column 1 for my calculation. So before I load that .dat file, do I need to delete all the other unwanted columns? If not, how do I selectively declare the column and ask python to do the math? </p>
  
  <p>an example of the .dat file would be
  <a href="https://drive.google.com/file/d/0B8Ki0GCZHcYbS01KUHZUaEgxMVE/view?usp=sharing" rel="noreferrer">data.dat</a></p>
  
  <p>I am new to python , so a little instruction to open , read and calculation would be appreciated.</p>
  
  <p>I have added the code I am using as a starter from your suggestion:</p>
  
  <pre><code>from sys import argv
  
  import pandas as pd
  
  
  
  script, filename = argv
  
  txt = open(filename)
  
  print "Here's your file %r:" % filename
  print txt.read()
  
  def your_func(row):
      return row['x-momentum'] / row['mass']
  
  columns_to_keep = ['mass', 'x-momentum']
  dataframe = pd.read_csv('~/Pictures', delimiter="," , usecols=columns_to_keep)
  dataframe['new_column'] = dataframe.apply(your_func, axis=1)
  </code></pre>
  
  <p>and also the error I get through it:</p>
  
  <pre><code>Traceback (most recent call last):
    File "flash.py", line 18, in &lt;module&gt;
      dataframe = pd.read_csv('~/Pictures', delimiter="," , usecols=columns_to_keep)
    File "/home/trina/anaconda2/lib/python2.7/site-packages/pandas/io/parsers.py", line 529, in parser_f
      return _read(filepath_or_buffer, kwds)
    File "/home/trina/anaconda2/lib/python2.7/site-packages/pandas/io/parsers.py", line 295, in _read
      parser = TextFileReader(filepath_or_buffer, **kwds)
    File "/home/trina/anaconda2/lib/python2.7/site-packages/pandas/io/parsers.py", line 612, in __init__
      self._make_engine(self.engine)
    File "/home/trina/anaconda2/lib/python2.7/site-packages/pandas/io/parsers.py", line 747, in _make_engine
      self._engine = CParserWrapper(self.f, **self.options)
    File "/home/trina/anaconda2/lib/python2.7/site-packages/pandas/io/parsers.py", line 1119, in __init__
      self._reader = _parser.TextReader(src, **kwds)
    File "pandas/parser.pyx", line 518, in pandas.parser.TextReader.__cinit__ (pandas/parser.c:5030)
  ValueError: No columns to parse from file
  </code></pre>