Skip to content
Advertisement

Transform matrix adjacency to Source, Target, Value in CSV file (python)

I have this CSV file, with adjacency matrix:

JavaScript

I want to transform to a new csv file, with the values of sorce, target, and value. For example:

JavaScript

Thanks!

Advertisement

Answer

If you replace the zeros with nan, you can use stack to achieve this.

JavaScript

Output

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement