如何使用 pandas 从目录中的 excel sheet 获取每一行值

How to get each row value from excel sheet in a directory using pandas

样本Excel:

name   empid   office
ABC    1111     CTS
XYZ    2222     TCS

我想要字典中的值,例如:

row1={ name='ABC', empid=1111, office='CTS' }
row2={ name='XYZ', empid=2222, office='TCS' }

使用循环,一次一行。

我的代码:

import pandas as pd
dfs = pd.read_excel('E://Python Workspace//pythonReadExcel.xlsx',  skiprows=0)
print(dfs.to_dict())

输出:

{'name': {0: 'ABC', 1: 'XYZ'}, 'empid': {0: 1111, 1: 2222}, 'office': {0: 'CTS', 1: 'TCS'}}

请帮我解决这个问题。

使用下面的代码:

df.to_dict(orient='records')

#output
[
  {'empid': 1111, 'name': 'ABC', 'office': 'CTS'}, 
  {'empid': 2222, 'name': 'XYZ', 'office': 'TCS'}
]