Skip to content

IO

read_csv(fname=None, header=False, index=False, t_col=2)

Read temporal edgelist and store it in a dictionary. Parameters: fname: directory of a dataset in .csv format or data object created from loading dgb/tgb datasets header: whether first line of data file is header index: whether the first column is row indices t_col: column indext for timestamps (0 or 2) ts_sorted: if data are sorted based on timestamp

Returns:

Name Type Description
temp_edgelist dict

A dictionary of edges and their frequency at each time interval

Source code in tgx/io/read.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def read_csv(fname: Union[str, object] = None, 
             header: bool = False,
             index: bool = False,
             t_col: int = 2,) -> dict:

    """
    Read temporal edgelist and store it in a dictionary.
    Parameters:
        fname: directory of a dataset in .csv format or data object created from loading dgb/tgb datasets 
        header: whether first line of data file is header
        index: whether the first column is row indices
        t_col: column indext for timestamps (0 or 2)
        ts_sorted: if data are sorted based on timestamp

    Returns:
        temp_edgelist: A dictionary of edges and their frequency at each time interval
    """

    start_col = 0
    if index:
        start_col = 1
        t_col += 1

    if t_col < 2:
        u_col = t_col + 1
    else:
        u_col = start_col
    v_col = u_col + 1

    cols_to_read = [u_col, v_col, t_col]

    if (isinstance(fname, str)):
        return _load_edgelist(fname, cols_to_read, header=header)
    elif isinstance(fname, type) or isinstance(fname, object):
        return _datasets_edgelist_loader(fname.data) 
    else:
        raise TypeError("Invalid input")