-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Add function to read DataFrame from clipboard across platforms #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
There's code in IPython for cross-platform clipboard access - it's intended for text, but it could probably be adapted: https://github.com/ipython/ipython/blob/master/IPython/core/hooks.py |
Thanks Thomas. I just copied that code into pandas.util.clipboard for now and added a new function |
Great, thanks. It seems to be working on Linux, copying from LO Calc, in Python 2 and 3. Although it does choke on a non-ascii character in Python 2. |
Ah, hm. If you figure out a patch to make it work let me know |
I think the trouble is that Python 2's CSV module doesn't handle unicode properly. There are some examples of wrappers in the csv library docs, if it's a serious concern. It's also likely to be dependent on platform. The Linux clipboard code returns unicode, the Mac code looks like it will return a byte string, and I've no idea about the Windows code. For that matter, I suspect that the Mac code will fail on Python 3 - |
I am having some issues with row labels containing unicode characters. I am using pandas 0.8.1, python 2.7.3. Here is the error message I am getting: UnicodeEncodeError Traceback (most recent call last) /usr/local/lib/python2.7/dist-packages/pandas/io/parsers.pyc in read_clipboard(*_kwargs) /usr/local/lib/python2.7/dist-packages/pandas/io/parsers.pyc in read_table(filepath_or_buffer, sep, dialect, header, index_col, names, skiprows, na_values, thousands, comment, parse_dates, keep_date_col, dayfirst, date_parser, nrows, iterator, chunksize, skip_footer, converters, verbose, delimiter, encoding, squeeze) /usr/local/lib/python2.7/dist-packages/pandas/io/parsers.pyc in _read(cls, filepath_or_buffer, kwds) /usr/local/lib/python2.7/dist-packages/pandas/io/parsers.pyc in init(self, f, delimiter, dialect, names, header, index_col, na_values, thousands, comment, parse_dates, keep_date_col, date_parser, dayfirst, chunksize, skiprows, skip_footer, converters, verbose, encoding, squeeze) /usr/local/lib/python2.7/dist-packages/pandas/io/parsers.pyc in _get_index_name(self, columns) /usr/local/lib/python2.7/dist-packages/pandas/io/parsers.pyc in _next_line(self) UnicodeEncodeError: 'ascii' codec can't encode character u'\xe7' in position 9: ordinal not in range(128) |
Use `.to_pydatetime` instead which has been in pandas since 0.10.0
No description provided.
The text was updated successfully, but these errors were encountered: