Pandas 模块 – 读写(3)-从剪贴板读写数据-read_clipboard/to_clipboard

目录

3. 从剪贴板读写数据(3)-read_clipboard/to_clipboard

3.1 .read_clipboard() 语法

3.2 .read_clipboard() 范例

3.3 .to_clipboard() 语法

2.4 .to_clipboard() 范例

  1. 从剪贴板读写数据-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 表格,并且对波浪区域中的数据进行了拷贝

Pandas 模块 - 读写(3)-从剪贴板读写数据-read_clipboard/to_clipboard

代码非常简单

import pandas as pd
data03=pd.read_clipboard()
data03

运行结果如下

Pandas 模块 - 读写(3)-从剪贴板读写数据-read_clipboard/to_clipboard

3.3 . <strong>to_clipboard() &#x8BED;&#x6CD5;</strong>

&#xA0; &#xA0; &#xA0; &#xA0;.<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() &#x8303;&#x4F8B;</strong>

稍微修改了一下数据,直接调用下面的代码,就可以黏贴了

data03.to_clipboard()

Pandas 模块 - 读写(3)-从剪贴板读写数据-read_clipboard/to_clipboard

”’

要是大家觉得写得还行,麻烦点个赞或者收藏吧,想给博客涨涨人气,非常感谢!

”’

Original: https://blog.csdn.net/u010701274/article/details/121425451
Author: 江南野栀子
Title: Pandas 模块 – 读写(3)-从剪贴板读写数据-read_clipboard/to_clipboard

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/679608/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球