python 读写excel
2022/6/18 1:52:08
本文主要是介绍python 读写excel,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
读取excel中的内容
def get_app_service(): df = pd.read_excel("test.xlsx",sheet_name='test') #读取excel对应的sheet data = list(df['service']) #读取一列 # print(data) return data
写数据到excel,生成新的excel
writer = pd.ExcelWriter("test.xlsx") df = pd.DataFrame(data_res) #data_res数据[[1,2,3],[1,2,3]] df.columns = title df.to_excel("test.xlsx",sheet_name=sheet_name,index=False) writer.save()
写数据到已存在的excel,不生成新的excel
df = pd.DataFrame(data_res) df.columns = title file_name = 'test.xlsx' try: wb = load_workbook(file_name) ws = wb[sheet_name] wb.remove(ws) wb.save(file_name) with pd.ExcelWriter(file_name, mode='a') as writer: df.to_excel(writer, sheet_name=sheet_name, index=False) except Exception as e: with pd.ExcelWriter(file_name, mode='a') as writer: df.to_excel(writer, sheet_name=sheet_name, index=False)
这篇关于python 读写excel的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门
- 2024-11-14Python编程入门指南
- 2024-11-13Python基础教程
- 2024-11-12Python编程基础指南
- 2024-11-12Python基础编程教程
- 2024-11-08Python编程基础与实践示例
- 2024-11-07Python编程基础指南
- 2024-11-06Python编程基础入门指南
- 2024-11-06怎么使用python 计算两个GPS的距离功能-icode9专业技术文章分享