I read one xlsx file in this i have two sheets and i want store in a dictionary of tuples but at the end of the tuples, I got extra comma.
my output: data_dict = {"sheet1":[('A',), ('B',), ('C',), ('D',)],"sheet2":[('A',), ('B',), ('C',), ('D',)]}
the correct output I want:
data_dict = {"sheet1":[('A'), ('B'), ('C'), ('D')],"sheet2":[('A'), ('B'), ('C'), ('D')]}
My current code is
import openpyxl
wb = load_workbook(xlsx_filename)
#print(wb)
data_dict = {}
for sheet in wb:
#print(sheet)
data_dict[sheet.title] = []
for row in sheet.rows:
#print(sheet.rows)
row_wise_data = tuple([cell.value for cell in row])
data_dict[sheet.title].append(row_wise_data)
#print(data_dict) # result in dictionary
return data_dict
wb.close()