pandas_utils.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:labutils 作者: networks-lab 项目源码 文件源码
def clip_df(df, tablefmt='html'):
    """
    Copy a dataframe as plain text to your clipboard.
    Probably only works on Mac. For format types see ``tabulate`` package
    documentation.

    :param pandas.DataFrame df: Input DataFrame.
    :param str tablefmt: What type of table?
    :return: None.
    """
    if tablefmt == 'material':
        html = tabulate.tabulate(df, headers=df.columns, tablefmt='html')
        html = html.replace('<table>', '<table class="mdl-data-table mdl-js-data-table">')
        header = '<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">\n<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css">\n<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script>'
        html = header + '\n' + html
    else:
        html = tabulate.tabulate(df, headers=df.columns, tablefmt=tablefmt)
    pyperclip.copy(html)
    print('Copied {} table to clipboard!'.format(tablefmt))
    return html
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号