import pandas as pd
def test(path):
print(path)
df = pd.read_excel(path) # 读取excel文档
title = df.columns # 输出title行
print(df.shape) # 显示行,列数
print(df.head(3)) # 打印前三行
print(df.tail(3)) #查看末三行
print(df.index.values) # 输出列的第一列
for i in df.index.values:
df_dict = df.loc[i, title].to_dict() # 将title和每行数据以字典的形式组装
print(df_dict)
if __name__ == '__main__':
test('./test.xlsx')
pandas操作excel表格生成标题和内容对应的字典格式
最新推荐文章于 2023-12-26 11:29:20 发布