pandas 数据框是否可以在新窗口中呈现? [英] Possible for pandas dataframe to be rendered in a new window?

查看:43
本文介绍了 pandas 数据框是否可以在新窗口中呈现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们都喜欢使用熊猫,以及数据框如何向我们展示数据片段.但是,在ipython笔记本中,有时很难查看所有数据,特别是如果包含太多列的话.

We all love using pandas and how the dataframe shows us a snippet of the data. However within the ipython notebook, sometimes it is difficult to view all the data especially if it contains too many columns.

只是想知道是否有一个选项在渲染图形时在新窗口(如Matplotlib)中查看数据框.

Was just wondering if there is an option to view the dataframe in a new window like Matplotlib when it renders its graph.

推荐答案

您可以创建一个包含整个表的HTML的临时文件,然后使用webbrowser模块打开.可能最好是简单地创建在新窗口中显示数据框的功能:

You can create a temporary file containing HTML of the whole table, and then use the webbrowser module to open in. It would probably be best to simply create a function for displaying data frames in a new window:

import webbrowser
import pandas as pd
from tempfile import NamedTemporaryFile

def df_window(df):
    with NamedTemporaryFile(delete=False, suffix='.html') as f:
        df.to_html(f)
    webbrowser.open(f.name)

df = pd.DataFrame({'a': [10, 10, 10, 11], 'b': [8, 8 ,8, 9]})
df_window(df)

编辑:在我的回答中此处我展示了如何使用JQuery + DataTables在新窗口中显示带有分页,搜索,排序和其他有趣内容的表格.

In my answer here I show how to display a table in a new window with pagination, search, sort and other cool stuff using JQuery+DataTables.

这篇关于 pandas 数据框是否可以在新窗口中呈现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆