def to_clipboard(obj, excel=None, sep=None, **kwargs):
 encoding = kwargs.pop('encoding', 'utf-8')
 if ((encoding is not None) and (encoding.lower().replace('-', '') != 'utf8')):
  raise ValueError('clipboard only supports utf-8 encoding')
 from pandas.util.clipboard import clipboard_set
 if (excel is None):
  excel = True
 if excel:
  try:
   if (sep is None):
    sep = ' DCTB '
   buf = StringIO()
   obj.to_csv(buf, sep=sep, encoding='utf-8', **kwargs)
   text = buf.getvalue()
   if PY2:
    text = text.decode('utf-8')
   clipboard_set(text)
   return
  except:
   pass
 if isinstance(obj, DataFrame):
  with option_context('display.max_colwidth', 999999):
   objstr = obj.to_string(**kwargs)
 else:
  objstr = str(obj)
 clipboard_set(objstr)

def to_clipboard ( obj , excel = None , sep = None , ** kwargs ) : encoding = kwargs . pop ( 'encoding' , 'utf-8' ) if ( ( encoding is not None ) and ( encoding . lower ( ) . replace ( '-' , '' ) != 'utf8' ) ) : raise ValueError ( 'clipboard only supports utf-8 encoding' ) from pandas . util . clipboard import clipboard_set if ( excel is None ) : excel = True if excel : try : if ( sep is None ) : sep = ' DCTB ' buf = StringIO ( ) obj . to_csv ( buf , sep = sep , encoding = 'utf-8' , ** kwargs ) text = buf . getvalue ( ) if PY2 : text = text . decode ( 'utf-8' ) clipboard_set ( text ) return except : pass if isinstance ( obj , DataFrame ) : with option_context ( 'display.max_colwidth' , 999999 ) : objstr = obj . to_string ( ** kwargs ) else : objstr = str ( obj ) clipboard_set ( objstr )
attempt to write text representation of object to the system clipboard the clipboard can be then pasted into excel for example .