Randomly Shuffle DataFrame Columns with Vaex

  • Share this:

Code introduction


This function uses the Vaex library to randomly shuffle the columns of a DataFrame.


Technology Stack : Vaex, Python

Code Type : Custom function

Code Difficulty : Intermediate


                
                    
def shuffleVaexColumns(df):
    """
    Shuffle the columns of a Vaex DataFrame.
    
    Args:
        df (vaex.DataFrame): The Vaex DataFrame to shuffle columns of.
        
    Returns:
        vaex.DataFrame: The DataFrame with shuffled columns.
    """
    import vaex as vx
    import random
    
    # Get the list of columns
    columns = df.columns
    
    # Shuffle the columns
    random.shuffle(columns)
    
    # Reorder the columns in the DataFrame
    shuffled_df = df[columns]
    
    return shuffled_df                
              
Tags: