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() 范例


3. 从剪贴板读写数据-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  .to_clipboard() 语法

       .to_clipboard()函数将对象复制到系统剪贴板。此函数将对象的文本表示形式写入系统剪贴板。

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.

2.4 .to_clipboard() 范例

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

data03.to_clipboard()

'''

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

'''

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

江南野栀子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值