def graph_from_cov_df(df, threshold=<NUM_LIT>, gain=<NUM_LIT>, n=None, class_dict=CLASSES):
n = n or len(df)<EOL>nodes = [{'<STR_LIT>': class_dict.get(name, <NUM_LIT:0>), "<STR_LIT:name>": name} for name in df.index.values][:n]<EOL>edges = []<EOL>for i, (row_name, row) in enumerate(df.iterrows()):<EOL><INDENT>for j, value in enumerate(row.values):<EOL><INDENT>if i > j and value * gain > threshold and i < n and j < n:<EOL><INDENT>edges += [{'<STR_LIT:source>': i, '<STR_LIT:target>': j, '<STR_LIT:value>': gain * value}]<EOL><DEDENT><DEDENT><DEDENT>return nodes, edges<EOL>
Compose pair of lists of dicts (nodes, edges) for the graph described by a DataFrame