如何从excel中检索数据并用python格式化?

如何从excel中检索数据并用python格式化?,python,excel,Python,Excel,我正在尝试从excel中检索数据,并将其转换为python中的以下格式: dataset={ 'User A': {'Lady in the Water': 2.5, 'Snakes on a Plane': 3.5, 'Just My Luck': 3.0, 'Superman Returns': 3.5,

我正在尝试从excel中检索数据,并将其转换为python中的以下格式:

 dataset={
        'User A': {'Lady in the Water': 2.5, 
                        'Snakes on a Plane': 3.5,
                        'Just My Luck': 3.0, 
                        'Superman Returns': 3.5, 
                        'You, Me and Dupree': 2.5,
                        'The Night Listener': 3.0},

        'Gene Seymour': {'Lady in the Water': 3.0, 
                        'Snakes on a Plane': 3.5,
                        'Just My Luck': 1.5,
                         'Superman Returns': 5.0,
                         'You, Me and Dupree': 3.5, 
                         'The Night Listener': 3.0
                        }}
excel文件看起来像什么

                User A  User B
 Lady in the Water  2.5 3
 Snakes on a Plane  3.5 3.5
 Just My Luck   3   1.5
 Superman Returns   3.5 5
 You, Me and Dupree 2.5 3.5
 The Night Listener 3   3

pandas
模块使这项工作变得非常简单:

import pandas as pd
df = pd.read_excel('workbook.xlsx', index_col=0)
dataset = df.to_dict()

在此代码中,
pd.read\u excel
函数从excel文件收集所有数据,并将其存储到一个变量中。数据帧具有大量非常强大的功能。其中一种方法是
to_dict
,它在这里的代码中用于将数据转换为嵌套字典。

熊猫
模块使这一过程非常简单:

import pandas as pd
df = pd.read_excel('workbook.xlsx', index_col=0)
dataset = df.to_dict()

在此代码中,
pd.read\u excel
函数从excel文件收集所有数据,并将其存储到一个变量中。数据帧具有大量非常强大的功能。其中一种方法是
to_dict
,它在这里的代码中用于将数据转换为嵌套字典。

另一种方法是通过openpyxl:

from openpyxl import Workbook
wb = load_workbook(filename = 'workbook.xlsx')
sheet_ranges = wb['cell range']
values = sheet_ranges['cell locations'].values()
data = values.to_dict()

另一种方法是通过openpyxl:

from openpyxl import Workbook
wb = load_workbook(filename = 'workbook.xlsx')
sheet_ranges = wb['cell range']
values = sheet_ranges['cell locations'].values()
data = values.to_dict()