目录
3. 从剪贴板读写数据(3)-read_clipboard/to_clipboard
- 从剪贴板读写数据-read_clipboard/to_clipboard
.read_clipboard() 可以在直接读取剪切板中的数据。你需要做的只是在某种文档例如 Excel 表格里按一下Ctrl+C,然后 read_clipboard就会读取到剪切板中的这些数据。
3.1 .read_clipboard() 语法
sep: 分隔符,默认为”\s+”
**kwargs:类似于 read_csv 中的参数
Help on function read_clipboard in module pandas.io.clipboards:
read_clipboard(sep='\\s+', **kwargs)
Read text from clipboard and pass to read_csv.
Parameters
----------
sep : str, default '\s+'
A string or regex delimiter. The default of '\s+' denotes
one or more whitespace characters.
**kwargs
See read_csv for the full argument list.
Returns
-------
DataFrame
A parsed DataFrame object.
3.2 .read_clipboard() 范例
我打开一个 Excel 表格,并且对波浪区域中的数据进行了拷贝
代码非常简单
import pandas as pd
data03=pd.read_clipboard()
data03
运行结果如下
3.3 . <strong>to_clipboard() 语法</strong>
       .<strong>to_clipboard()</strong>
函数将对象复制到系统剪贴板。此函数将对象的文本表示形式写入系统剪贴板。
Help on function to_clipboard in module pandas.core.generic:
to_clipboard(self, excel: 'bool_t' = True, sep: 'Optional[str]' = None, **kwargs) -> 'None'
Copy object to the system clipboard.
Write a text representation of object to the system clipboard.
This can be pasted into Excel, for example.
Parameters
----------
excel : bool, default True
Produce output in a csv format for easy pasting into excel.
- True, use the provided separator for csv pasting.
- False, write a string representation of the object to the clipboard.
sep : str, default
'\t'
Field delimiter.
**kwargs
These parameters will be passed to DataFrame.to_csv.
<strong>2.4 .to_clipboard() 范例</strong>
稍微修改了一下数据,直接调用下面的代码,就可以黏贴了
data03.to_clipboard()
”’
要是大家觉得写得还行,麻烦点个赞或者收藏吧,想给博客涨涨人气,非常感谢!
”’
Original: https://blog.csdn.net/u010701274/article/details/121425451
Author: 江南野栀子
Title: Pandas 模块 – 读写(3)-从剪贴板读写数据-read_clipboard/to_clipboard
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/679608/
转载文章受原作者版权保护。转载请注明原作者出处!