pyspark.pandas.Series.to_clipboard ¶
-
Series.
to_clipboard
( excel : bool = True , sep : Optional [ str ] = None , ** kwargs : Any ) → None [source] ¶ -
将对象复制到系统剪贴板。
将对象的文本表示写入系统剪贴板。 例如,这可以粘贴到Excel中。
注意
此方法仅应在预期结果DataFrame较小的情况下使用,因为所有数据都会加载到驱动程序的内存中。
- Parameters
-
- excel bool, default True
-
-
True,使用提供的分隔符,以csv格式写入,便于轻松粘贴到Excel中。
-
False,将对象的字符串表示写入剪贴板。
-
-
sep
str, default
'\t'
-
字段分隔符。
- **kwargs
-
这些参数将被传递给 DataFrame.to_csv。
另请参阅
-
read_clipboard
-
从剪贴板读取文本。
注释
您的平台要求。
-
Linux : xclip , 或 xsel (使用 gtk 或 PyQt4 模块)
-
Windows : 无
-
OS X : 无
示例
将DataFrame的内容复制到剪贴板。
>>> df = ps.DataFrame([[1, 2, 3], [4, 5, 6]], columns=['A', 'B', 'C']) >>> df.to_clipboard(sep=',') ... # Wrote the following to the system clipboard: ... # ,A,B,C ... # 0,1,2,3 ... # 1,4,5,6
我们可以通过传递关键字 index 并将其设置为false来省略索引。
>>> df.to_clipboard(sep=',', index=False) ... # Wrote the following to the system clipboard: ... # A,B,C ... # 1,2,3 ... # 4,5,6
此函数也适用于 Series:
>>> df = ps.Series([1, 2, 3, 4, 5, 6, 7], name='x') >>> df.to_clipboard(sep=',') ... # Wrote the following to the system clipboard: ... # 0, 1 ... # 1, 2 ... # 2, 3 ... # 3, 4 ... # 4, 5 ... # 5, 6 ... # 6, 7