World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITians, only for AI Learners.
Designed by IITians, only for AI Learners.
New to InsideAIML? Create an account
Employer? Create an account
There are several ways to read excel cell values as a list:
import openpyxl # load the workbook wb = openpyxl.load_workbook('example.xlsx') # select the sheet sheet = wb.active # read the cell values and store them in a list cell_values = [] for row in sheet.iter_rows(): for cell in row: cell_values.append(cell.value) print(cell_values)
2. Using pandas library:
import pandas as pd # read the excel file df = pd.read_excel('example.xlsx') # convert the dataframe to a list cell_values = df.values.tolist() print(cell_values)
3. Using xlrd library:
import xlrd # open the workbook wb = xlrd.open_workbook('example.xlsx') # select the sheet sheet = wb.sheet_by_index(0) # read the cell values and store them in a list cell_values = [] for row in range(sheet.nrows): for col in range(sheet.ncols): cell_values.append(sheet.cell(row, col).value) print(cell_values)