import pandas as pd
def read_file():
file_path = r'C:\test_excel.xlsx'
data_file = pd.read_excel(file_path)
for index, row in data_file.iterrows():
print(index)
print(row["columnA"])
pass
def export_to_excel():
final_list = [["a", "b"], ["c", "d"]]
output_file = r'C:\test_excel.xlsx'
title_list = ['columnA', 'columnB']
title_tup = tuple(title_list)
res = pd.DataFrame(columns=title_tup)
for i in range(len(final_list)):
res.loc[i + 1] = final_list[i]
res.to_excel(output_file, index=False)
if __name__ == '__main__':
read_file()
export_to_excel()
Python中使用pandas实现excel的读取和写入
最新推荐文章于 2024-03-26 12:50:05 发布
本文介绍了如何使用Python的pandas库读取和写入Excel文件,包括从文件中读取数据并打印,以及将列表数据结构导出到Excel表格中指定列名。
摘要由CSDN通过智能技术生成