Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
391 views
in Technique[技术] by (71.8m points)

python - 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:Python33libsite-packagespandasioclipboard.py in read_clipboard(**kwargs)
     16     from pandas.io.parsers import read_table
     17     text = clipboard_get()
---> 18     return read_table(StringIO(text), **kwargs)
     19 
     20 

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

in C:python33Libsite-packagespandasioclipboard.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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...