old_scripts/basicML.py
def filter_nucs(df, nuc_set, top_n):
    """
    for each instance (row), keep only top 200 values, replace rest with 0
    
    Parameters
    ----------
    df : dataframe of nuclide concentrations
    nuc_set : set of top_n nuclides
    top_n : number of nuclides to sort and filter by

    Returns
    -------
    top_n_df : dataframe that has values only for the top_n nuclides of the set 
               nuc_set in each row

    """
    
    # To filter further, have to reconstruct the df into a new one
    # Found success appending each row to a new df as a series
    top_n_df = pd.DataFrame(columns=tuple(nuc_set))
    for case, conc in df.iterrows():
        top_n_series = conc.sort_values(ascending=False)[:top_n]
        nucs = top_n_series.index.values
        # some top values in test set aren't in nuc set, so need to delete those
        del_list = list(set(nucs) - nuc_set)
        top_n_series.drop(del_list, inplace=True)
        filtered_row = conc.filter(items=top_n_series.index.values)
        top_n_df = top_n_df.append(filtered_row)
    # replace NaNs with 0, bc scikit don't take no NaN
    top_n_df.fillna(value=0, inplace=True)
    return top_n_df

    for each instance (row), keep only top 200 values, replace rest with 0
    
    Parameters
    ----------
    df : dataframe of nuclide concentrations
    nuc_set : set of top_n nuclides
    top_n : number of nuclides to sort and filter by

    Returns
    -------
    top_n_df : dataframe that has values only for the top_n nuclides of the set 
               nuc_set in each row

    
for each instance (row), keep only top 200 values, replace rest with 0
Parameters

df : dataframe of nuclide concentrations
nuc_set : set of top_n nuclides
top_n : number of nuclides to sort and filter by

Returns

top_n_df : dataframe that has values only for the top_n nuclides of the set
nuc_set in each row
for each instance ( row ) keep only top 200 values replace rest with 0 Parameters df : dataframe of nuclide concentrations nuc_set : set of top_n nuclides top_n : number of nuclides to sort and filter by Returns top_n_df : dataframe that has values only for the top_n nuclides of the set nuc_set in each row
def filter_nucs(df, nuc_set, top_n):
    top_n_df = pd.DataFrame(columns=tuple(nuc_set))
    for case, conc in df.iterrows():
        top_n_series = conc.sort_values(ascending=False)[:top_n]
        nucs = top_n_series.index.values
        del_list = list(set(nucs) - nuc_set)
        top_n_series.drop(del_list, inplace=True)
        filtered_row = conc.filter(items=top_n_series.index.values)
        top_n_df = top_n_df.append(filtered_row)
    top_n_df.fillna(value=0, inplace=True)
    return top_n_df
def filter_nucs ( df , nuc_set , top_n ) : top_n_df = pd . DataFrame ( columns = tuple ( nuc_set ) ) for case , conc in df . iterrows ( ) : top_n_series = conc . sort_values ( ascending = False ) [ : top_n ] nucs = top_n_series . index . values del_list = list ( set ( nucs ) - nuc_set ) top_n_series . drop ( del_list , inplace = True ) filtered_row = conc . filter ( items = top_n_series . index . values ) top_n_df = top_n_df . append ( filtered_row ) top_n_df . fillna ( value = 0 , inplace = True ) return top_n_df
for each instance (row), keep only top 200 values, replace rest with 0
Parameters
for each instance ( row ) keep only top 200 values replace rest with 0 Parameters
"""
    for each instance (row), keep only top 200 values, replace rest with 0
    
    Parameters
    ----------
    df : dataframe of nuclide concentrations
    nuc_set : set of top_n nuclides
    top_n : number of nuclides to sort and filter by

    Returns
    -------
    top_n_df : dataframe that has values only for the top_n nuclides of the set 
               nuc_set in each row

    """ # To filter further, have to reconstruct the df into a new one # Found success appending each row to a new df as a series # some top values in test set aren't in nuc set, so need to delete those # replace NaNs with 0, bc scikit don't take no NaN
df
nuc_set
top_n