title: Pandas: error when reading CSV file using `sep` and `comment` arguments
body: <h1>Situation</h1>
  
  <p>I have to create a pandas dataframe from a CSV-like file that has the following characteristics:</p>
  
  <ul>
  <li>The delimiter used by the file can be either comma or space, and I don't know in advance which one the file will have.</li>
  <li>At the top of the file there can be one or more comment lines, which start with <code>#</code>.</li>
  </ul>
  
  <h1>Problem</h1>
  
  <p>I have tried to tackle this with the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow noreferrer"><code>pd.read_csv</code></a> method with arguments <code>sep=None</code> and <code>comment='#'</code>. To my understanding the <code>sep=None</code> argument tells pandas to auto-detect the delimiter character and the <code>comment='#'</code> argument tells pandas that all lines starting with <code>#</code> are comment lines that should be ignored.</p>
  
  <p>These arguments work fine when used individually. However when I use them both together, then I receive the error message <code>TypeError: expected string or bytes-like object</code>. The following code example demonstrates this:</p>
  
  <pre><code>from io import StringIO
  import pandas as pd
  
  # Simulated data file contents
  tabular_data = (
      '# Data generated on 04 May 2017\n'
      'col1,col2,col3\n'
      '5.9,7.8,3.2\n'
      '7.1,0.4,8.1\n'
      '9.4,5.4,1.9\n'
  )
  
  # This works
  df1 = pd.read_csv(StringIO(tabular_data), sep=None)
  print(df1)
  
  # This also works
  df2 = pd.read_csv(StringIO(tabular_data), comment='#')
  print(df2)
  
  # This will give an error
  df3 = pd.read_csv(StringIO(tabular_data), sep=None, comment='#')
  print(df3)
  </code></pre>
  
  <p>Unfortunately I don't really understand what is triggering the error. Would anyone here be able to give me some help to resolve this problem?</p>