eccpy/tools.py
def reindex_df_so_selected_cols_are_first(df, selected_cols, raise_error=True):
    """ Reindex DataFrame so that selected columns are displayed first (on the left)

    Parameters
    ----------
    df : pandas DataFrame
        Pandas 2D DataFrame with unique columns
    selected_cols : list
        List of strings representing the column names to place first

    Returns
    -------
    df : pandas DataFrame
        Original DataFrame with altered column order
    """

    # convert columns to list
    col_list_orig = list(df.columns)
    # remove the list_cols_to_place_first from the original columns
    for col in selected_cols:
        if col in col_list_orig:
            col_list_orig.remove(col)
        else:
            if raise_error == True:
                raise ValueError("\n\nError, reindex_df_so_selected_cols_are_first, '%s' not in columns" % col)
            else:
                print("\n\nError, reindex_df_so_selected_cols_are_first, '%s' not in columns" % col)
    # join to create desired list of columns, and reindex the dataframe
    col_list_final = selected_cols + col_list_orig
    return df.reindex(columns = col_list_final)
 Reindex DataFrame so that selected columns are displayed first (on the left)

    Parameters
    ----------
    df : pandas DataFrame
        Pandas 2D DataFrame with unique columns
    selected_cols : list
        List of strings representing the column names to place first

    Returns
    -------
    df : pandas DataFrame
        Original DataFrame with altered column order
    
Reindex DataFrame so that selected columns are displayed first (on the left)
Parameters

df : pandas DataFrame
Pandas 2D DataFrame with unique columns
selected_cols : list
List of strings representing the column names to place first

Returns

df : pandas DataFrame
Original DataFrame with altered column order
Reindex DataFrame so that selected columns are displayed first ( on the left ) Parameters df : pandas DataFrame Pandas 2D DataFrame with unique columns selected_cols : list List of strings representing the column names to place first Returns df : pandas DataFrame Original DataFrame with altered column order
def reindex_df_so_selected_cols_are_first(df, selected_cols, raise_error=True):
    col_list_orig = list(df.columns)
    for col in selected_cols:
        if col in col_list_orig:
            col_list_orig.remove(col)
        else:
            if raise_error == True:
                raise ValueError("\n\nError, reindex_df_so_selected_cols_are_first, '%s' not in columns" % col)
            else:
                print("\n\nError, reindex_df_so_selected_cols_are_first, '%s' not in columns" % col)
    col_list_final = selected_cols + col_list_orig
    return df.reindex(columns = col_list_final)
def reindex_df_so_selected_cols_are_first ( df , selected_cols , raise_error = True ) : col_list_orig = list ( df . columns ) for col in selected_cols : if col in col_list_orig : col_list_orig . remove ( col ) else : if raise_error == True : raise ValueError ( "\n\nError, reindex_df_so_selected_cols_are_first, '%s' not in columns" % col ) else : print ( "\n\nError, reindex_df_so_selected_cols_are_first, '%s' not in columns" % col ) col_list_final = selected_cols + col_list_orig return df . reindex ( columns = col_list_final )
Reindex DataFrame so that selected columns are displayed first (on the left)
Parameters
Reindex DataFrame so that selected columns are displayed first ( on the left ) Parameters
""" Reindex DataFrame so that selected columns are displayed first (on the left)

    Parameters
    ----------
    df : pandas DataFrame
        Pandas 2D DataFrame with unique columns
    selected_cols : list
        List of strings representing the column names to place first

    Returns
    -------
    df : pandas DataFrame
        Original DataFrame with altered column order
    """ # convert columns to list # remove the list_cols_to_place_first from the original columns # join to create desired list of columns, and reindex the dataframe
df
selected_cols
raise_error