## 下载所需示例数据 ## 1. https://labfile.oss.aliyuncs.com/courses/791/my_data.xlsx ## 2. https://labfile.oss.aliyuncs.com/courses/791/phase_detector.xlsx ## 3. https://labfile.oss.aliyuncs.com/courses/791/phase_detector2.xlsx from xlrd import open_workbook x_data1 = [] y_data1 = [] wb = open_workbook('phase_detector.xlsx') for s in wb.sheets(): print('Sheet:', s.name) for row in range(s.nrows): print('the row is:', row) values = [] for col in range(s.ncols): values.append(s.cell(row, col).value) print(values) x_data1.append(values[0]) y_data1.append(values[1])
时间: 2024-04-28 18:21:57 浏览: 125
感谢您的问题。这段代码是用于读取 Excel 文件中的数据,并将其存储到列表中。其中,第一个示例数据文件的文件名为“my_data.xlsx”,第二个示例数据文件的文件名为“phase_detector.xlsx”,第三个示例数据文件的文件名为“phase_detector2.xlsx”。代码通过使用 xlrd 库中的 open_workbook 函数打开 Excel 文件,然后遍历每个工作表中的每一行,并将每行的第一列和第二列的值分别存储到 x_data1 和 y_data1 列表中。在代码中,使用了 print 函数来输出读取的数据,以便进行调试。如果您需要在代码中使用这些数据,只需要将文件名替换为您所需的文件名即可。
阅读全文
相关推荐
















