import pandas as pd import pymysql from datetime import datetime # 定义一个自增的全局变量 counter = 1 def increment(): global counter counter += 1 return counter # 调用函数并打印结果 # print(get_current_date()) def get_array(): # 读取 Excel 文件 file_path = 'D:\\test1.xlsx' df = pd.read_excel(file_path) # 新建一个空数组 arr1= [] # 遍历 DataFrame 的每一行,将每一行数据添加到空数组 for index, row in df.iterrows(): arr1.append(row.tolist()) # print(medicine_array) # 遍历array,将index为1的值置空,将index为2的值删除,并插到列表第一个 for sub_array in arr1: sub_array[1] = None sub_array.insert(0, sub_array.pop(2)) # print(sub_array) # 遍历arr1 将值nan 替换为None for sub_array in medicine_array: for i, value in enumerate(sub_array): if pd.isna(value): sub_array[i] = None # 添加需要的值 for i, row in enumerate(medicine_array): temp = increment() row.insert(0,temp) row.append(1) row.append(temp) row.append(None) # print(f"Row {i}: {row}") return medicine_array # print(get_array())
标签:None,sub,excel,数组,print,array,pandas,row From: https://www.cnblogs.com/nizi-ver1/p/18528449