0

Here is my code:

import numpy as np
import pandas as pd
import networkx as nx

df = pd.read_excel(r"/path/to/file.xlsx", sheet_name="Sheet4")
df.edge=nx.from_pandas_edgelist(df,source='Abrev')
print(list(enumerate_all_cliques(nx.Graph(df.edge))))

if gives me a key error of KeyError: 'Abrev' for this code but I also tried changing 'Abrev' to 0 and deleting the source='Abrev' all together and just get a slight different error for each; 'KeyError: 0 'KeyError: 'source'

Sample contents of excel file;

+---+---+---+---+---+
|   | A | B | C | D |
+---+---+---+---+---+
| A | 0 | 1 | 1 | 0 |
+---+---+---+---+---+
| B | 1 | 0 | 0 | 1 |
+---+---+---+---+---+
| C | 1 | 0 | 0 | 1 |
+---+---+---+---+---+
| D | 0 | 1 | 1 | 0 |
+---+---+---+---+---+
mewspoon
  • 37
  • 8
  • 1
    which columns do you have in the excel file? You may are simply looking for [`nx.from_pandas_adjacency`](https://networkx.org/documentation/stable//reference/generated/networkx.convert_matrix.from_pandas_adjacency.html)? – Sparky05 Mar 25 '21 at 15:55

1 Answers1

0

just add the nx.from_pandas_adjacencyand you forgot a nx. in front of the enumerate_all_cliques

import numpy as np
import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt

df = pd.read_excel(r"/path/to/file.xlsx", sheet_name="Sheet4",index_col=0,usecols = "A:E")
df.edge=nx.from_pandas_adjacency(df)
print(list(nx.enumerate_all_cliques(nx.Graph(df.edge))))
mewspoon
  • 37
  • 8