KOTA ITO

Generation

generate functionWed, 07 Dec 2022

データテーブルから隣接行列を作成する

def make_matrix(df, columns_from='from', columns_to='to'): df = df.copy() df['value'] = 1 matrix = df.pivot_table( index=columns_from, columns=columns_to, values='value') matrix = matrix.fillna(0) return matrix.as_matrix() make_matrix(df)

Questions about programming?Chat with your personal AI assistant