You can download this code by clicking the button below.
This code is now available for download.
This function randomly selects a specified number of columns from a Vaex DataFrame.
Technology Stack : Vaex
Code Type : Function
Code Difficulty : Intermediate
import vaex as vx
def random_select_columns(df, num_columns=3):
"""
Selects random columns from a Vaex DataFrame.
Args:
- df (vx.DataFrame): The Vaex DataFrame from which to select columns.
- num_columns (int): The number of columns to select. Default is 3.
Returns:
- list: A list of randomly selected column names.
"""
columns = list(df.columns)
selected_columns = random.sample(columns, min(num_columns, len(columns)))
return selected_columns