将excel邻接矩阵转换为在python中可读

2024-06-10 14:24:24 发布

您现在位置:Python中文网/ 问答频道 /正文

只是需要一些帮助,将excel电子表格矩阵转换为python的networkx模块可读的表单。我试过使用xlrd,但我不知道。请帮忙,如果我需要更具体的问题请告诉我。 到目前为止,我使用的代码是:

import xlrd

loc = 'C:\Users\kchen\Desktop\UNSW UNI\Honours\Publishing papers\EVC\Brain matrix\brain 1 matrix.xlsx'

wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
sheet.cell_value(0, 0)

assert isinstance(sheet.nrows, object)
print(sheet.nrows)

loc = 'C:\Users\kchen\Desktop\UNSW UNI\Honours\Publishing papers\EVC\Brain matrix\brain 1 matrix.xlsx'

wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)

# For row 0 and column 0
sheet.cell_value(0, 0)

# Extracting number of columns
print(sheet.ncols)

Tags: usersmatrixlocsheetunidesktopwbpublishing