Pandas HoloView:为数据框中的每一列创建箱线图

Pandas HoloView:为数据框中的每一列创建箱线图,pandas,dataframe,bokeh,holoviews,Pandas,Dataframe,Bokeh,Holoviews,我可以使用Pandas方法创建以下箱线图: 尽管如此,如果我尝试使用HoloViews'和Bokeh作为后端来做同样的事情,它对单个列来说效果很好: import holoviews as hv from holoviews import opts hv.extension('bokeh') hv.BoxWhisker( data=df['Col1'], vdims='Col1' ) 但是,只要我尝试添加另一列,就会出现以下错误: hv.BoxWhisker( d

我可以使用Pandas方法创建以下箱线图:

尽管如此,如果我尝试使用HoloViews'和Bokeh作为后端来做同样的事情,它对单个列来说效果很好:

import holoviews as hv
from holoviews import opts
hv.extension('bokeh')

hv.BoxWhisker(
    data=df['Col1'],
    vdims='Col1'
)

但是,只要我尝试添加另一列,就会出现以下错误:

hv.BoxWhisker(
    data=df[['Col1', 'Col2']]
)

DataError: None of the available storage backends were able to support the supplied data format. PandasInterface raised following error:

 unsupported operand type(s) for +: 'NoneType' and 'int'

PandasInterface expects tabular data, for more information on supported datatypes see http://holoviews.org/user_guide/Tabular_Datasets.html

我无法理解HoloViews是否存在问题,或者我无法正确应用syntaxis。

我不确定如何从本机HoloViews BoxWhisker界面实现您想要的功能,该界面是为整洁的数据而设置的,而不是为一组类似的独立列设置的。同时,您可以像使用native.plot()调用一样使用hvPlot:


我还推荐詹姆斯·贝德纳尔的答案,,它正在使用。HvPlot构建在HoloView之上:

import hvplot.pandas
df.hvplot.box()

但是,如果要在HoloView中而不是在hvPlot中执行此操作,则必须使用数据才能在一列中获取所有列名,在另一列中获取所有值。

此代码适用于示例数据:

hv.boxwhisber(df.melt(),kdims='variable',vdims='value')

我不知道hvPlot API,谢谢。您提到的“整洁数据”让我在HoloViews文档中进行了更多的研究,主要是关于的部分,最终我能够在将数据从“宽”格式转换为“长”格式后,在没有
df.hvplot.box()
的情况下使其工作。正如@james提到的,我能够在“转换”后使其工作我的数据采用与您相同的方式(即从宽格式到长格式)。唯一的区别是我使用了
pd.wide\u to_long()
而不是
pd.melt()
。您的建议是否与此特定示例相关,或者您认为应该尽可能使用hvPlot而不是直全息视图?hvPlot中是否存在已知的限制,迫使您退回到HoloView?我几乎总是使用hvPlot而不是HoloView,尤其是在进行快速数据分析时。可能有HoloViews更好的用例,但我发现hvPlot非常好用,特别是当你有多个列时,不需要做任何熔化等。
hv.BoxWhisker(
    data=df[['Col1', 'Col2']]
)

DataError: None of the available storage backends were able to support the supplied data format. PandasInterface raised following error:

 unsupported operand type(s) for +: 'NoneType' and 'int'

PandasInterface expects tabular data, for more information on supported datatypes see http://holoviews.org/user_guide/Tabular_Datasets.html