title: How to escape the escapechar in pandas to_csv
body: <p>I'm trying to write dataframes to CSV.  A lot of the incoming data is user-generated and may contain special characters.  I can set <code>escapechar='\\'</code> (for example), but then if there is a backslash in the data it gets written as <code>"\"</code> which gets interpreted as an escaped double-quote as opposed to a string containing a backslash.  How can I escape the escapechar (ie, how can I have to_csv write <code>\\</code> by escaping the backslash?)</p>
  
  <p>Example code:</p>
  
  <pre><code>import pandas as pd
  import io, csv
  
  data = [[1, "\\", "text"]] 
  df = pd.DataFrame(data)
  
  sIo = io.StringIO()
  df.to_csv(
      sIo,
      index=False,
      sep=',',
      header=False,
      quoting=csv.QUOTE_MINIMAL,
      doublequote=False,
      escapechar='\\'
  )
  sioText = sIo.getvalue()
  print(sioText)
  </code></pre>
  
  <p>Actual output:</p>
  
  <pre><code>1,"\",text
  </code></pre>
  
  <p>What I need:</p>
  
  <pre><code>1,"\\",text
  </code></pre>
  
  <p>The engineering use case that creates the constraints is that this will be some core code for moving data from one system to another.  I won't know the format of the data in advance and won't have much control over it (any column could contain the escape character), and I can't control the escape character on the other side so the actual output will be read as an error.  Hence the original question of "how do you escape the escape character."</p>
  
  <p>For reference this parameter's definition in the pandas docs is:</p>
  
  <pre><code>escapecharstr, default None
  String of length 1. Character used to escape sep and quotechar when appropriate.
  </code></pre>