lux.core package¶
Submodules¶
lux.core.frame module¶
-
class
lux.core.frame.
LuxDataFrame
(*args, **kw)[source]¶ A subclass of pd.DataFrame that supports all dataframe operations while housing other variables and functions for generating visual recommendations.
-
expire_metadata
()[source]¶ Expire all saved metadata to trigger a recomputation the next time the data is required.
-
groupby
(*args, **kwargs)[source]¶ Group DataFrame using a mapper or by a Series of columns.
A groupby operation involves some combination of splitting the object, applying a function, and combining the results. This can be used to group large amounts of data and compute operations on these groups.
Parameters: - by (mapping, function, label, or list of labels) – Used to determine the groups for the groupby.
If
by
is a function, it’s called on each value of the object’s index. If a dict or Series is passed, the Series or dict VALUES will be used to determine the groups (the Series’ values are first aligned; see.align()
method). If an ndarray is passed, the values are used as-is to determine the groups. A label or list of labels may be passed to group by the columns inself
. Notice that a tuple is interpreted as a (single) key. - axis ({0 or 'index', 1 or 'columns'}, default 0) – Split along rows (0) or columns (1).
- level (int, level name, or sequence of such, default None) – If the axis is a MultiIndex (hierarchical), group by a particular level or levels.
- as_index (bool, default True) – For aggregated output, return object with group labels as the index. Only relevant for DataFrame input. as_index=False is effectively “SQL-style” grouped output.
- sort (bool, default True) – Sort group keys. Get better performance by turning this off. Note this does not influence the order of observations within each group. Groupby preserves the order of rows within each group.
- group_keys (bool, default True) – When calling apply, add group keys to index to identify pieces.
- squeeze (bool, default False) –
Reduce the dimensionality of the return type if possible, otherwise return a consistent type.
Deprecated since version 1.1.0.
- observed (bool, default False) – This only applies if any of the groupers are Categoricals. If True: only show observed values for categorical groupers. If False: show all values for categorical groupers.
- dropna (bool, default True) –
If True, and if group keys contain NA values, NA values together with row/column will be dropped. If False, NA values will also be treated as the key in groups
New in version 1.1.0.
Returns: Returns a groupby object that contains information about the groups.
Return type: DataFrameGroupBy
See also
resample()
- Convenience method for frequency conversion and resampling of time series.
Notes
See the user guide for more.
Examples
>>> df = pd.DataFrame({'Animal': ['Falcon', 'Falcon', ... 'Parrot', 'Parrot'], ... 'Max Speed': [380., 370., 24., 26.]}) >>> df Animal Max Speed 0 Falcon 380.0 1 Falcon 370.0 2 Parrot 24.0 3 Parrot 26.0 >>> df.groupby(['Animal']).mean() Max Speed Animal Falcon 375.0 Parrot 25.0
Hierarchical Indexes
We can groupby different levels of a hierarchical index using the level parameter:
>>> arrays = [['Falcon', 'Falcon', 'Parrot', 'Parrot'], ... ['Captive', 'Wild', 'Captive', 'Wild']] >>> index = pd.MultiIndex.from_arrays(arrays, names=('Animal', 'Type')) >>> df = pd.DataFrame({'Max Speed': [390., 350., 30., 20.]}, ... index=index) >>> df Max Speed Animal Type Falcon Captive 390.0 Wild 350.0 Parrot Captive 30.0 Wild 20.0 >>> df.groupby(level=0).mean() Max Speed Animal Falcon 370.0 Parrot 25.0 >>> df.groupby(level="Type").mean() Max Speed Type Captive 210.0 Wild 185.0
We can also choose to include NA in group keys or not by setting dropna parameter, the default setting is True:
>>> l = [[1, 2, 3], [1, None, 4], [2, 1, 3], [1, 2, 2]] >>> df = pd.DataFrame(l, columns=["a", "b", "c"])
>>> df.groupby(by=["b"]).sum() a c b 1.0 2 3 2.0 2 5
>>> df.groupby(by=["b"], dropna=False).sum() a c b 1.0 2 3 2.0 2 5 NaN 1 4
>>> l = [["a", 12, 12], [None, 12.3, 33.], ["b", 12.3, 123], ["a", 1, 1]] >>> df = pd.DataFrame(l, columns=["a", "b", "c"])
>>> df.groupby(by="a").sum() b c a a 13.0 13.0 b 12.3 123.0
>>> df.groupby(by="a", dropna=False).sum() b c a a 13.0 13.0 b 12.3 123.0 NaN 12.3 33.0
- by (mapping, function, label, or list of labels) – Used to determine the groups for the groupby.
If
-
render_widget
(renderer: str = 'altair', input_current_vis='')[source]¶ Generate a LuxWidget based on the LuxDataFrame
Structure of widgetJSON:
{
‘current_vis’: {}, ‘recommendation’: [
{
‘action’: ‘Correlation’, ‘description’: “some description”, ‘vspec’: [
{Vega-Lite spec for vis 1}, {Vega-Lite spec for vis 2}, …]
}, … repeat for other actions
]
}
Parameters: - renderer (str, optional) – Choice of visualization rendering library, by default “altair”
- input_current_vis (lux.LuxDataFrame, optional) – User-specified current vis to override default Current Vis, by default
-
save_as_html
(filename: str = 'export.html') → None[source]¶ Save dataframe widget as static HTML file
Parameters: filename (str) – Filename for the output HTML file
-
set_data_type
(types: dict)[source]¶ Set the data type for a particular attribute in the dataframe overriding the automatically-detected type inferred by Lux
Parameters: types (dict) – Dictionary that maps attribute/column name to a specified Lux Type. Possible options: “nominal”, “quantitative”, “id”, and “temporal”. Example
df = pd.read_csv(“https://raw.githubusercontent.com/lux-org/lux-datasets/master/data/absenteeism.csv”) df.set_data_type({“ID”:”id”,
“Reason for absence”:”nominal”})
-
set_intent_as_vis
(vis: lux.vis.Vis.Vis)[source]¶ Set intent of the dataframe based on the intent of a Vis
Parameters: vis (Vis) – Input Vis object
-
exported
¶ Get selected visualizations as exported Vis List
Notes
Convert the _selectedVisIdxs dictionary into a programmable VisList Example _selectedVisIdxs :
{‘Correlation’: [0, 2], ‘Occurrence’: [1]}indicating the 0th and 2nd vis from the Correlation tab is selected, and the 1st vis from the Occurrence tab is selected.
Returns: When there are no exported vis, return empty list -> [] When all the exported vis is from the same tab, return a VisList of selected visualizations. -> VisList(v1, v2…) When the exported vis is from the different tabs, return a dictionary with the action name as key and selected visualizations in the VisList. -> {“Enhance”: VisList(v1, v2…), “Filter”: VisList(v5, v7…), ..} Return type: Union[Dict[str,VisList], VisList]
-