<commit_before>from __future__ import division

import pandas as pd

from plotting import NUMERIC_TYPES



def get_numeric_features(df):
    float_feature_names = [feature for feature in df.columns
                           if df[feature].dtype in NUMERIC_TYPES]
    return df[float_feature_names]


def arff_to_df(arff):
    rows = []
    for row in arff[0]:
        rows.append(list(row))
    attributes = [x for x in arff[1]]
    return pd.DataFrame(rows, columns=attributes)


def get_nominal_integer_dict(nominal_vals):
    """
    Takes a set of nominal values (non-numeric)
    and returns a dictionary that maps each value<commit_msg>Add functional data manipulation methods<commit_after>from __future__ import division

import pandas as pd

from plotting import NUMERIC_TYPES


def exclude(df, exclude):
    """
    Return a DataFrame with a set of feature excluded
    """
    keep = [column for column in df.columns
            if column not in exclude]
    return df[keep]


def partition(df, partition_function):
    """
    Separate a dataframe row-wise based on the
    value of the supplied partition function
    """

    partition_values = df.apply(partition_function, axis=1)
    return df.groupby(partition_values)


def split(df, columns):
    """
    Separate a dataframe column-wise and turn a tuple
    of all the given columns on one side and the remaining
    columns on the other side
    """

    left = columns
    right = [column for column in df.columns
             if column not in left]

    return (df[left], df[right])
    #partition_values = df.apply(partition_function, axis=1)
    #return df.groupby(partition_values)


def get_numeric_features(df):
    float_feature_names = [feature for feature in df.columns
                           if df[feature].dtype in NUMERIC_TYPES]
    return df[float_feature_names]


def arff_to_df(arff):
    rows = []
    for row in arff[0]:
        rows.append(list(row))
    attributes = [x for x in arff[1]]
    return pd.DataFrame(rows, columns=attributes)


def get_nominal_integer_dict(nominal_vals):
    """
    Takes a set of nominal values (non-numeric)
    and returns a dictionary that maps each value
{'fraction_non_alphanumeric': 0.076007326007326, 'fraction_numerical': 0.0027472527472527475, 'mean_word_length': 3.099437148217636, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '990578', 'n_tokens_mistral': 663, 'n_tokens_neox': 642, 'n_words': 217}