Exemple #1
0
def test_nest_column_between():
    nest(df,
         columns_between=['sepal length (cm)', 'petal width (cm)'],
         key='data_nest')
Exemple #2
0
import pandas as pd
from sklearn import datasets
from tidyframe import nest, unnest

iris = datasets.load_iris()
df = pd.DataFrame(iris['data'], columns=iris.feature_names)
df['target'] = iris.target
df['target2'] = list(map(lambda x: str(x + 1), df.target))
columns = ['target', 'target2']
df2 = nest(df, columns, key='data_nest', copy=True)


def test_unnest_basic():
    unnest(df2)[df.columns]


def test_unnest_list():
    df_string = pd.DataFrame()
    df_string['a'] = list('11223')
    df_string['b'] = list('22334')
    df_string['c'] = ['a', 'bb', 'ccc', 'dddd', 'eeeee']
    df_string['d'] = df_string['c'].map(lambda x: list(x))
    unnest(df_string)


def test_unnest_split():
    df_comma = pd.DataFrame({'a': list('12'), "b": ['A,B,C', 'D,E,F,G']})
    df_comma['b_split'] = df_comma['b'].apply(lambda x: x.split(','))
    unnest(df_comma)

Exemple #3
0
def test_nest_by_index_minus():
    nest(df, columns_minus=df.columns[4:6], key='data_nest', copy=True).head()
Exemple #4
0
def test_nest_by_index():
    nest(df, df.columns[:4], key='data_nest', copy=True)
Exemple #5
0
def test_nest_group_by():
    nest(df.groupby(['target', 'target2']), key='data_nest', copy=True)
Exemple #6
0
def test_nest_columns():
    nest(df,
         columns_minus=df.columns[4:6].tolist(),
         key='data_nest',
         copy=True)
Exemple #7
0
def test_nest_columns():
    nest(df, columns, key='data_nest', copy=True)