API 参考#
cuxfilter 的两个主要组件是 DataFrame 用于将仪表盘连接到 cuDF 支持的 DataFrame,以及 Dashboard 用于设置仪表盘选项。
DataFrame#
- class cuxfilter.dataframe.DataFrame(data)#
一个 cuxfilter GPU DataFrame 对象
- 属性:
- data
- edges
方法
dashboard
(charts[, sidebar, layout, theme, ...])创建一个 cuxfilter.DashBoard 对象
from_arrow
(dataframe_location)从磁盘读取 arrow 文件作为 cuxfilter.DataFrame
from_dataframe
(dataframe)从 cudf.DataFrame/dask_cudf.DataFrame 创建 cuxfilter.DataFrame(零拷贝引用)
load_graph
(graph)从图对象创建 cudf.DataFrame/dask_cudf.DataFrame(零拷贝引用)
preprocess_data
validate_dask_index
- dashboard(charts: list, sidebar: list = [], layout=<class 'cuxfilter.layouts.layouts.Layout0'>, theme=<class 'cuxfilter.themes.default.LightTheme'>, title='Dashboard', data_size_widget=True, warnings=False, layout_array=None)#
创建一个 cuxfilter.DashBoard 对象
- 参数:
- charts: list
cuxfilter.charts 列表
- layout: cuxfilter.layouts
- theme: cuxfilter.themes, 默认 cuxfilter.themes.default.
- title: str
仪表盘标题,默认为“Dashboard”
- data_size_widget: boolean
标志,用于确定是否显示仪表盘中当前选定的数据点数量,默认为 True
- warnings: boolean
标志,用于禁用或启用与布局相关的运行时警告,默认为 False
- 返回:
- cuxfilter.DashBoard 对象
示例
>>> import cudf >>> import cuxfilter >>> from cuxfilter.charts import bokeh >>> df = cudf.DataFrame( >>> { >>> 'key': [0, 1, 2, 3, 4], >>> 'val':[float(i + 10) for i in range(5)] >>> } >>> ) >>> cux_df = cuxfilter.DataFrame.from_dataframe(df) >>> line_chart_1 = bokeh.line( >>> 'key', 'val', data_points=5, add_interaction=False >>> )
>>> # create a dashboard object >>> d = cux_df.dashboard([line_chart_1])
- classmethod from_arrow(dataframe_location)#
从磁盘读取 arrow 文件作为 cuxfilter.DataFrame
- 参数:
- dataframe_location: str 或 arrow 内存表
- 返回:
- cuxfilter.DataFrame 对象
示例
从磁盘读取 arrow 文件作为 DataFrame
>>> import cuxfilter >>> import pyarrow as pa
>>> # create a temporary arrow table >>> arrowTable = pa.Table.from_arrays([['foo', 'bar']], names=['name'])
>>> # read arrow table, can also ready .arrow file paths directly >>> cux_df = cuxfilter.DataFrame.from_arrow(df)
- classmethod from_dataframe(dataframe)#
从 cudf.DataFrame/dask_cudf.DataFrame 创建 cuxfilter.DataFrame(零拷贝引用)
- 参数:
- dataframe_location: cudf.DataFrame 或 dask_cudf.DataFrame
- 返回:
- cuxfilter.DataFrame 对象
示例
从 cudf.DataFrame/dask_cudf.DataFrame 读取 DataFrame
>>> import cuxfilter >>> import cudf >>> cudf_df = cudf.DataFrame( >>> { >>> 'key': [0, 1, 2, 3, 4], >>> 'val':[float(i + 10) for i in range(5)] >>> } >>> ) >>> cux_df = cuxfilter.DataFrame.from_dataframe(cudf_df)
- classmethod load_graph(graph)#
从图对象创建 cudf.DataFrame/dask_cudf.DataFrame(零拷贝引用)
- 参数:
- 元组对象 (nodes, edges),其中 nodes 和 edges 是 cudf DataFrames
- 返回:
- cuxfilter.DataFrame 对象
示例
从 cugraph 对象加载图
>>> import cuxfilter >>> import cudf, cugraph >>> edges = cudf.DataFrame( >>> { >>> 'source': [0, 1, 2, 3, 4], >>> 'target':[0,1,2,3,4], >>> 'weight':[4,4,2,6,7], >>> } >>> ) >>> G = cugraph.Graph() >>> G.from_cudf_edgelist(edges, destination='target') >>> cux_df = cuxfilter.DataFrame.load_graph((G.nodes(), G.edges()))
从 (nodes, edges) 加载图
>>> import cuxfilter >>> import cudf >>> nodes = cudf.DataFrame( >>> { >>> 'vertex': [0, 1, 2, 3, 4], >>> 'x':[0,1,2,3,4], >>> 'y':[4,4,2,6,7], >>> 'attr': [0,1,1,1,1] >>> } >>> ) >>> edges = cudf.DataFrame( >>> { >>> 'source': [0, 1, 2, 3, 4], >>> 'target':[0,1,2,3,4], >>> 'weight':[4,4,2,6,7], >>> } >>> ) >>> cux_df = cuxfilter.DataFrame.load_graph((nodes,edges))
DashBoard#
- class cuxfilter.dashboard.DashBoard(charts=[], sidebar=[], dataframe=None, layout=<class 'cuxfilter.layouts.layouts.Layout0'>, theme=<class 'cuxfilter.themes.default.LightTheme'>, title='Dashboard', data_size_widget=True, show_warnings=False, layout_array=None)#
一个 cuxfilter GPU DashBoard 对象。示例 ——–
创建一个仪表盘
>>> import cudf >>> import cuxfilter >>> from cuxfilter.charts import bokeh, panel_widgets >>> df = cudf.DataFrame( >>> {'key': [0, 1, 2, 3, 4], 'val':[float(i + 10) for i in range(5)]} >>> ) >>> cux_df = cuxfilter.DataFrame.from_dataframe(df) >>> line_chart_1 = bokeh.line( >>> 'key', 'val', data_points=5, add_interaction=False >>> ) >>> line_chart_2 = bokeh.bar( >>> 'val', 'key', data_points=5, add_interaction=False >>> ) >>> sidebar_widget = panel_widgets.card("test") >>> d = cux_df.dashboard(charts=[line_chart_1, line_chart_2], >>> sidebar=[sidebar_widget]) >>> d `cuxfilter DashBoard [title] Markdown(str) [chart0] Markdown(str, sizing_mode='stretch_both'), ['nav']) [chart1] Column(sizing_mode='scale_both', width=1600) [0] Bokeh(Figure) [chart2] Column(sizing_mode='scale_both', width=1600) [0] Bokeh(Figure)` >>> # d.app() for serving within notebook cell, >>> # d.show() for serving as a separate web-app >>> d.app() #or d.show() displays interactive dashboard
进行一些视觉查询/交叉过滤
- 属性:
charts
仪表盘中的图表,以字典形式。
queried_indices
只读属性 queried_indices 返回 self._query_str_dict 中所有查询索引列的合并索引,作为 cudf.Series 或 dask_cudf.Series。
- server
方法
add_charts
([charts, sidebar])在仪表盘初始化后,向其添加更多图表。
app
([sidebar_width, width, height])在 Jupyter Notebook 中使用 bokeh 后端服务器运行仪表盘。
export
()根据仪表盘当前的过滤状态导出 cudf.DataFrame。
show
([notebook_url, port, threaded, ...])在 Jupyter Notebook 中使用 bokeh 后端服务器运行仪表盘。
stop
()停止 bokeh 服务器
- add_charts(charts=[], sidebar=[])#
在仪表盘初始化后,向其添加更多图表。
- 参数:
- charts: list
cuxfilter.charts 对象的列表
- sidebar: list
cuxfilter.charts.panel_widget 对象的列表
注意
添加图表后,刷新仪表盘应用标签页以查看更新后的图表。类型为 widget 的图表不能添加到侧边栏,但 widget 可以添加到 charts(主布局)
示例
>>> import cudf >>> import cuxfilter >>> from cuxfilter.charts import bokeh, panel_widgets >>> df = cudf.DataFrame( >>> { >>> 'key': [0, 1, 2, 3, 4], >>> 'val':[float(i + 10) for i in range(5)] >>> } >>> ) >>> cux_df = cuxfilter.DataFrame.from_dataframe(df) >>> line_chart_1 = bokeh.line( >>> 'key', 'val', data_points=5, add_interaction=False >>> ) >>> d = cux_df.dashboard([line_chart_1]) >>> line_chart_2 = bokeh.bar( >>> 'val', 'key', data_points=5, add_interaction=False >>> ) >>> d.add_charts(charts=[line_chart_2]) >>> # or >>> d.add_charts(charts=[], sidebar=[panel_widgets.card("test")])
- app(sidebar_width=280, width=1200, height=800)#
在 Jupyter Notebook 中使用 bokeh 后端服务器运行仪表盘。
- 参数:
- sidebar_width: int, 可选, 默认为 280
侧边栏宽度(像素)
- width: int, 可选, 默认为 1200
仪表盘宽度(像素)
- height: int, 可选, 默认为 800
仪表盘高度(像素)
示例
>>> import cudf >>> import cuxfilter >>> from cuxfilter.charts import bokeh >>> df = cudf.DataFrame( >>> { >>> 'key': [0, 1, 2, 3, 4], >>> 'val':[float(i + 10) for i in range(5)] >>> } >>> ) >>> cux_df = cuxfilter.DataFrame.from_dataframe(df) >>> line_chart_1 = bokeh.line( >>> 'key', 'val', data_points=5, add_interaction=False >>> ) >>> d = cux_df.dashboard([line_chart_1]) >>> d.app(sidebar_width=200, width=1000, height=450)
- property charts#
仪表盘中的图表,以字典形式。
- export()#
根据仪表盘当前的过滤状态导出 cudf.DataFrame。
同时打印仪表盘当前状态的查询字符串。
- 返回:
- 基于仪表盘当前过滤状态的 cudf.DataFrame。
示例
>>> import cudf >>> import cuxfilter >>> from cuxfilter.charts import bokeh >>> df = cudf.DataFrame( >>> { >>> 'key': [0, 1, 2, 3, 4], >>> 'val':[float(i + 10) for i in range(5)] >>> } >>> ) >>> cux_df = cuxfilter.DataFrame.from_dataframe(df) >>> line_chart_1 = bokeh.line( >>> 'key', 'val', data_points=5, add_interaction=False >>> ) >>> line_chart_2 = bokeh.bar( >>> 'val', 'key', data_points=5, add_interaction=False >>> ) >>> d = cux_df.dashboard( >>> [line_chart_1, line_chart_2], >>> layout=cuxfilter.layouts.double_feature >>> ) >>> # d.app() for serving within notebook cell, >>> # d.show() for serving as a separate web-app >>> d.app() #or d.show() displays interactive dashboard
>>> queried_df = d.export() final query 2<=key<=4
- show(notebook_url='http://localhost:8888', port=0, threaded=False, service_proxy=None, sidebar_width=280, height=800, **kwargs)#
在 Jupyter Notebook 中使用 bokeh 后端服务器运行仪表盘。
- 参数:
- notebook_url: str, 可选, 默认为 localhost:8888
您希望以 Web 应用形式运行仪表盘的 URL,
包括端口号。
如果本地运行,可以使用 localhost 代替 IP。
- port: int, 可选
必须是开放端口
- service_proxy: str, 可选, 默认为 None,
可用选项: jupyterhub
- threaded: boolean, 可选, 默认为 False
是否以线程模式运行服务器
- sidebar_width: int, 可选, 默认为 280
侧边栏宽度(像素)
- height: int, 可选, 默认为 800
仪表盘高度(像素)
- **kwargs: dict, 可选
传递给服务器的额外关键字参数
示例
>>> import cudf >>> import cuxfilter >>> from cuxfilter.charts import bokeh >>> df = cudf.DataFrame( >>> { >>> 'key': [0, 1, 2, 3, 4], >>> 'val':[float(i + 10) for i in range(5)] >>> } >>> ) >>> cux_df = cuxfilter.DataFrame.from_dataframe(df) >>> line_chart_1 = bokeh.line( >>> 'key', 'val', data_points=5, add_interaction=False >>> ) >>> d = cux_df.dashboard([line_chart_1]) >>> d.show(url='localhost:8889')
- stop()#
停止 bokeh 服务器