Skip to content

Commit 74bf0d0

Browse files
dandxy89TomAugspurger
authored andcommitted
DOC: update the pandas.core.generic.NDFrame.to_clipboard docstring (#20134)
1 parent ffe297c commit 74bf0d0

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

pandas/core/generic.py

+45-13
Original file line numberDiff line numberDiff line change
@@ -2041,26 +2041,58 @@ def to_pickle(self, path, compression='infer',
20412041
protocol=protocol)
20422042

20432043
def to_clipboard(self, excel=True, sep=None, **kwargs):
2044-
"""
2045-
Attempt to write text representation of object to the system clipboard
2044+
r"""
2045+
Copy object to the system clipboard.
2046+
2047+
Write a text representation of object to the system clipboard.
20462048
This can be pasted into Excel, for example.
20472049
20482050
Parameters
20492051
----------
2050-
excel : boolean, defaults to True
2051-
if True, use the provided separator, writing in a csv
2052-
format for allowing easy pasting into excel.
2053-
if False, write a string representation of the object
2054-
to the clipboard
2055-
sep : optional, defaults to tab
2056-
other keywords are passed to to_csv
2052+
excel : bool, default True
2053+
- True, use the provided separator, writing in a csv format for
2054+
allowing easy pasting into excel.
2055+
- False, write a string representation of the object to the
2056+
clipboard.
2057+
2058+
sep : str, default ``'\t'``
2059+
Field delimiter.
2060+
**kwargs
2061+
These parameters will be passed to DataFrame.to_csv.
2062+
2063+
See Also
2064+
--------
2065+
DataFrame.to_csv : Write a DataFrame to a comma-separated values
2066+
(csv) file.
2067+
read_clipboard : Read text from clipboard and pass to read_table.
20572068
20582069
Notes
20592070
-----
2060-
Requirements for your platform
2061-
- Linux: xclip, or xsel (with gtk or PyQt4 modules)
2062-
- Windows: none
2063-
- OS X: none
2071+
Requirements for your platform.
2072+
2073+
- Linux : `xclip`, or `xsel` (with `gtk` or `PyQt4` modules)
2074+
- Windows : none
2075+
- OS X : none
2076+
2077+
Examples
2078+
--------
2079+
Copy the contents of a DataFrame to the clipboard.
2080+
2081+
>>> df = pd.DataFrame([[1, 2, 3], [4, 5, 6]], columns=['A', 'B', 'C'])
2082+
>>> df.to_clipboard(sep=',')
2083+
... # Wrote the following to the system clipboard:
2084+
... # ,A,B,C
2085+
... # 0,1,2,3
2086+
... # 1,4,5,6
2087+
2088+
We can omit the the index by passing the keyword `index` and setting
2089+
it to false.
2090+
2091+
>>> df.to_clipboard(sep=',', index=False)
2092+
... # Wrote the following to the system clipboard:
2093+
... # A,B,C
2094+
... # 1,2,3
2095+
... # 4,5,6
20642096
"""
20652097
from pandas.io import clipboards
20662098
clipboards.to_clipboard(self, excel=excel, sep=sep, **kwargs)

0 commit comments

Comments
 (0)