DataFrame数据转为list,再逐行写入Excel
首先使用np.array()函数把DataFrame转化为np.ndarray(),
再利用tolist()函数把np.ndarray()转为list,
示例代码如下:
# -*- coding:utf-8-*- import numpy as np import pandas as pd df = pd.DataFrame(pd.read_excel('All.xlsx')) #pd.dataframe df_data = np.array(df) #np.ndarray() df_list=df_data.tolist() #list print(df_list) print(type(df_list))
再逐行写入Excel:
for i in range(len(df_list)): sheet1.append(df_list[i])