Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Chuyển Spreadsheet thành Python Dictionary

Dễ nhất: dùng pandas library. ExcelFile.parse() → to_dict().

Ví dụ

from pandas import *
xls = ExcelFile('my_file.xls')
data = xls.parse(xls.sheet_names[0])
print(data.to_dict())

Kết quả: {'id': 10, 'name': "John"}