Python pandas 读取 excel文件
参考:https://www.jb51.net/article/283627.htm
# 单纯导出一个数据集 def exportData_pandas(excelFile='output.xlsx'): try: # data = {'Name': ['Alice', 'Bob', 'Charlie'], # 'Age': [25, 28, 30]} name_list = [] age_list =[] for i in range(10): name_list.append('name'+str(i)) age_list.append('age' + str(i)) data = {'Name':name_list,'Age':age_list} df = pd.DataFrame(data) # 导出 DataFrame 到 Excel 文件 df.to_excel(excelFile, index=False) except Exception as e: print(e) # 以增加方式导出数据集合,在导出之前,output.xlsx已经有数据 def exportData_pandas_append(excelFile='output.xlsx'): try: original_data = pd.read_excel(excelFile) name_list = [] age_list =[] for i in range(10): name_list.append('name'+str(i)) age_list.append('age' + str(i)) data = {'Name':name_list,'Age':age_list} data2 = pd.DataFrame(data) # 将新数据与旧数据合并起来 save_data = original_data.append(data2) save_data.to_excel(excelFile, index=False) except Exception as e: print(e)