Note that the although the solution to this error was using a string charcter instead of regex, pandas also raises this error when using from __future__ import unicode_literals
with valid unicode characters. As of 2015-11-16, release 0.16.2, this error is still a known bug in pandas:
"to_csv chokes if not passed sep as a string, even when encoding is set to unicode" #6035
For example, where df is a pandas DataFrame:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import pandas as pd
df.to_csv(pdb_seq_fp, sep='', encoding='utf-8')
TypeError: "delimiter" must be an 1-character string
Using a byte lteral with the specified encoding (default utf-8 with Python 3) -*- coding: utf-8 -*-
will resolve this in pandas 0.16.2: (b''
) —I haven't tested with previous versions or 0.17.0.
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import pandas as pd
df.to_csv(pdb_seq_fp, sep=b'', encoding='utf-8')
(Note that with versions 0.13.0 - ???, it was necessary to use pandas.compat import u
; but by 0.16.2 the byte literal is the way to go.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…