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
评论列表
文章目录