### Install Vaex using Conda or Pip Source: https://vaex.io/docs/index Install the Vaex library and its dependencies using either the conda package manager from the conda-forge channel or the pip package manager. These commands will set up the necessary environment to start working with Vaex. ```bash conda install -c conda-forge vaex ``` ```bash pip install --upgrade vaex ``` -------------------------------- ### Import Vaex and Load an Example Dataset Source: https://vaex.io/docs/index This snippet demonstrates how to import the vaex library and load the built-in example dataset using the `vaex.example()` function. This is the initial step for working with vaex. ```python import vaex df = vaex.example() # open the example dataset provided with vaex ``` -------------------------------- ### Calculate 1D Binned Statistics with Vaex Source: https://vaex.io/docs/index Vaex can efficiently calculate statistics over a regular grid. This example computes the mean of a column, binned by another column 'x' into 32 bins within the range of -10 to 10. ```python df.mean(df.r, binby=df.x, shape=32, limits=[-10, 10]) # create statistics on a regular grid (1d) ``` -------------------------------- ### Create a Vaex Expression Source: https://vaex.io/docs/index Vaex expressions are computed lazily and do not consume memory until they are needed. This example creates a new expression by adding two DataFrame columns together. The output shows a preview of the expression's values. ```python some_expression = df.x + df.z some_expression ``` -------------------------------- ### Filter and Select Data from a Vaex DataFrame Source: https://vaex.io/docs/index This example shows how to filter a vaex DataFrame to create a new view without copying data. It first creates a filtered DataFrame `df_negative` for rows where `x < 0`, and then selects the first five rows and only the 'x' and 'y' columns from this filtered view. ```python df_negative = df[df.x < 0] # easily filter your DataFrame, without making a copy df_negative[:5][['x', 'y']] # take the first five rows, and only the 'x' and 'y' column (no memory copy!) ``` -------------------------------- ### Calculate 2D Binned Statistics with Vaex Source: https://vaex.io/docs/index Statistics can also be calculated on a 2D grid by passing a list of columns to the `binby` argument. This example demonstrates calculating the mean and count (histogram) for a 2D grid defined by columns 'x' and 'y'. ```python df.mean(df.r, binby=[df.x, df.y], shape=32, limits=[-10, 10]) # or 2d df.count(df.r, binby=[df.x, df.y], shape=32, limits=[-10, 10]) # or 2d counts/histogram ``` -------------------------------- ### Generate a Heatmap with Vaex Source: https://vaex.io/docs/index Vaex includes convenient visualization functions for quick plotting. This snippet uses the `.viz.heatmap` accessor to generate and display a heatmap of columns 'x' and 'y'. ```python df.viz.heatmap(df.x, df.y, show=True); # make a plot quickly ``` -------------------------------- ### Display a Vaex DataFrame Source: https://vaex.io/docs/index To inspect the contents of a vaex DataFrame in an interactive environment like a Jupyter notebook, simply reference the DataFrame variable. This will render a formatted table showing a preview of the data. ```python df # will pretty print the DataFrame ``` -------------------------------- ### Import NumPy for Vaex Computations Source: https://vaex.io/docs/index Import the NumPy library to be used with vaex. Many NumPy functions can be applied directly to vaex DataFrames and columns, enabling lazy, on-the-fly computations without significant memory overhead. ```python import numpy as np ``` -------------------------------- ### Add a Virtual Column to a Vaex DataFrame Source: https://vaex.io/docs/index An expression can be added to a DataFrame as a virtual column, which is computed on-the-fly and does not use additional memory. This snippet adds the previously created expression as a new column 'r' and then calculates the mean for both a normal and a virtual column. ```python df['r'] = some_expression # add a (virtual) column that will be computed on the fly df.mean(df.x), df.mean(df.r) # calculate statistics on normal and virtual columns ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.