Puggie Puggie - 5 months ago 28
Python Question

Pandas read_clipboard broken in pandas 0.12?

Since I updated pandas from version 0.11 to 0.12, read_clipboard doesn't seem to work anymore:

import pandas as pd

df = pd.read_clipboard()
TypeError Traceback (most recent call last)
<ipython-input-2-6dead334eb54> in <module>()
----> 1 df = pd.read_clipboard()

C:\Python33\lib\site-packages\pandas\io\clipboard.py in read_clipboard(**kwargs)
16 from pandas.io.parsers import read_table
17 text = clipboard_get()
---> 18 return read_table(StringIO(text), **kwargs)

TypeError: initial_value must be str or None, not bytes

What I did was:

  • Open a csv file in Excel 2010

  • Copy a range of cells, including headers

  • Perform read_clipboard in iPython Qt console as described in above code block

After downgrading to 0.11, this procedure worked fine again. I'm using pandas for python 3.3 Win7 32 bit.

Is this a bug in pandas? Any suggestions on how to resolve this issue?


Its a bug in the string presented to py3; I'll fix it in master, but you can do this local edit.

in C:\python33\Lib\site-packages\pandas\io\clipboard.py

after text = clipboard_get()

add text = text.decode('UTF-8')

apparently the clipboard routine gives you back bytes (and not a string) in py3