pycatflow/input.py
def prepare_data(data, columns_data, node_data, category_data, orientation, sort_field, prefix):
    """
    Arranges the data into a new format to make is usable for the flow visualisation.

    Parameters:
    data (dict): original data transformed to a dict
    columns_data (str): Name of the column with temporal data (None if orientation="vertical")
    node_data (str): which column to use as nodes in the graph 
    category_data (str): Name of the column containing optional categories of nodes
    orientation (str): Horizontal if the temporal data are in one columns, vertical if the temporal data are the name of the column
    sort_field (str): Optionally provide the name of a column determining the order of the time_field columns
    prefix (str): delete an unwanted prefix out of the data

    Returns:
    (dict): Dictionary of parsed data
    """
    new_data = {}
    if orientation == 'horizontal':
        if sort_field is None:
            columns = detect_dtype(data[columns_data], prefix)
        else:
            columns = []
            n_sort_field = [int(x) for x in data[sort_field]]
            [columns.append(data[columns_data][n_sort_field.index(x)]) for x in sorted(n_sort_field) if x not in columns]
            
        tags = data[node_data]
        counts = [[x for x in tags].count(x) for x in tags]
        if category_data is not None:
            for l in columns:
                d = {x: (z, y) for t, x, y, z in zip(data[columns_data], tags, data[category_data], counts) if l == t}
                new_data[l] = {k: v for k, v in d.items()}
        else:
            for l in columns:
                d = {x: z for t, x, z in zip(data[columns_data], tags, counts) if l == t}
                new_data[l] = {k: v for k, v in d.items()}
    else:
        if category_data is not None:
            columns = detect_dtype(list(data.keys()), prefix)
            
            tags = []
            for l in columns:
                [tags.append(y) for y in data[l]]
            counts = [[x for x in tags].count(x) for x in tags]
            for l in columns:
                data[l+"_count"] = [counts[tags.index(x)] for x in data[l]]
                d = {x: (z, y) for x, y, z in zip(data[l], data[l + category_data], data[l + "_count"])}
                new_data[l] = {k: v for k, v in d.items()}
        else:
            types = detect_dtype(list(data.keys()), prefix)
            columns = detect_dtype(list(data.keys()), prefix)
            tags = []
            for l in columns:
                [tags.append(y) for y in data[l]]
            counts = [[x for x in tags].count(x) for x in tags]
            for l in columns:
                data[l+"_count"] = [counts[tags.index(x)] for x in data[l]]
                d = {x: z for x, z in zip(data[l], data[l+"_count"])}
                new_data[l] = {k: v for k, v in d.items()}
    return new_data

    Arranges the data into a new format to make is usable for the flow visualisation.

    Parameters:
    data (dict): original data transformed to a dict
    columns_data (str): Name of the column with temporal data (None if orientation="vertical")
    node_data (str): which column to use as nodes in the graph 
    category_data (str): Name of the column containing optional categories of nodes
    orientation (str): Horizontal if the temporal data are in one columns, vertical if the temporal data are the name of the column
    sort_field (str): Optionally provide the name of a column determining the order of the time_field columns
    prefix (str): delete an unwanted prefix out of the data

    Returns:
    (dict): Dictionary of parsed data
    
Arranges the data into a new format to make is usable for the flow visualisation.

Dictionary of parsed data
Arranges the data into a new format to make is usable for the flow visualisation . Dictionary of parsed data
def prepare_data(data, columns_data, node_data, category_data, orientation, sort_field, prefix):
    new_data = {}
    if orientation == 'horizontal':
        if sort_field is None:
            columns = detect_dtype(data[columns_data], prefix)
        else:
            columns = []
            n_sort_field = [int(x) for x in data[sort_field]]
            [columns.append(data[columns_data][n_sort_field.index(x)]) for x in sorted(n_sort_field) if x not in columns]
        tags = data[node_data]
        counts = [[x for x in tags].count(x) for x in tags]
        if category_data is not None:
            for l in columns:
                d = {x: (z, y) for t, x, y, z in zip(data[columns_data], tags, data[category_data], counts) if l == t}
                new_data[l] = {k: v for k, v in d.items()}
        else:
            for l in columns:
                d = {x: z for t, x, z in zip(data[columns_data], tags, counts) if l == t}
                new_data[l] = {k: v for k, v in d.items()}
    else:
        if category_data is not None:
            columns = detect_dtype(list(data.keys()), prefix)
            tags = []
            for l in columns:
                [tags.append(y) for y in data[l]]
            counts = [[x for x in tags].count(x) for x in tags]
            for l in columns:
                data[l+"_count"] = [counts[tags.index(x)] for x in data[l]]
                d = {x: (z, y) for x, y, z in zip(data[l], data[l + category_data], data[l + "_count"])}
                new_data[l] = {k: v for k, v in d.items()}
        else:
            types = detect_dtype(list(data.keys()), prefix)
            columns = detect_dtype(list(data.keys()), prefix)
            tags = []
            for l in columns:
                [tags.append(y) for y in data[l]]
            counts = [[x for x in tags].count(x) for x in tags]
            for l in columns:
                data[l+"_count"] = [counts[tags.index(x)] for x in data[l]]
                d = {x: z for x, z in zip(data[l], data[l+"_count"])}
                new_data[l] = {k: v for k, v in d.items()}
    return new_data
def prepare_data ( data , columns_data , node_data , category_data , orientation , sort_field , prefix ) : new_data = { } if orientation == 'horizontal' : if sort_field is None : columns = detect_dtype ( data [ columns_data ] , prefix ) else : columns = [ ] n_sort_field = [ int ( x ) for x in data [ sort_field ] ] [ columns . append ( data [ columns_data ] [ n_sort_field . index ( x ) ] ) for x in sorted ( n_sort_field ) if x not in columns ] tags = data [ node_data ] counts = [ [ x for x in tags ] . count ( x ) for x in tags ] if category_data is not None : for l in columns : d = { x : ( z , y ) for t , x , y , z in zip ( data [ columns_data ] , tags , data [ category_data ] , counts ) if l == t } new_data [ l ] = { k : v for k , v in d . items ( ) } else : for l in columns : d = { x : z for t , x , z in zip ( data [ columns_data ] , tags , counts ) if l == t } new_data [ l ] = { k : v for k , v in d . items ( ) } else : if category_data is not None : columns = detect_dtype ( list ( data . keys ( ) ) , prefix ) tags = [ ] for l in columns : [ tags . append ( y ) for y in data [ l ] ] counts = [ [ x for x in tags ] . count ( x ) for x in tags ] for l in columns : data [ l + "_count" ] = [ counts [ tags . index ( x ) ] for x in data [ l ] ] d = { x : ( z , y ) for x , y , z in zip ( data [ l ] , data [ l + category_data ] , data [ l + "_count" ] ) } new_data [ l ] = { k : v for k , v in d . items ( ) } else : types = detect_dtype ( list ( data . keys ( ) ) , prefix ) columns = detect_dtype ( list ( data . keys ( ) ) , prefix ) tags = [ ] for l in columns : [ tags . append ( y ) for y in data [ l ] ] counts = [ [ x for x in tags ] . count ( x ) for x in tags ] for l in columns : data [ l + "_count" ] = [ counts [ tags . index ( x ) ] for x in data [ l ] ] d = { x : z for x , z in zip ( data [ l ] , data [ l + "_count" ] ) } new_data [ l ] = { k : v for k , v in d . items ( ) } return new_data
Arranges the data into a new format to make is usable for the flow visualisation.
Arranges the data into a new format to make is usable for the flow visualisation .
"""
    Arranges the data into a new format to make is usable for the flow visualisation.

    Parameters:
    data (dict): original data transformed to a dict
    columns_data (str): Name of the column with temporal data (None if orientation="vertical")
    node_data (str): which column to use as nodes in the graph 
    category_data (str): Name of the column containing optional categories of nodes
    orientation (str): Horizontal if the temporal data are in one columns, vertical if the temporal data are the name of the column
    sort_field (str): Optionally provide the name of a column determining the order of the time_field columns
    prefix (str): delete an unwanted prefix out of the data

    Returns:
    (dict): Dictionary of parsed data
    """
data
columns_data
node_data
category_data
orientation
sort_field
prefix