import numpy as np
import pandas as pd
A = np.array([[1, 2], [3, 2], [1, 1], [3, 5], [5,2]])
data = pd.DataFrame(A)
writer = pd.ExcelWriter('A.xlsx') # 写入Excel文件
data.to_excel(writer, 'page_1', float_format='%.5f') # ‘page_1’是写入excel的sheet名
writer.save()
writer.close()
运行后的结果为:
图片.png
其中,to_excel()的参数主要有:
to_excel(self, excel_writer, sheet_name='Sheet1', na_rep='', float_format=None,columns=None,
header=True, index=True, index_label=None,startrow=0, startcol=0, engine=None,
merge_cells=True, encoding=None,inf_rep='inf', verbose=True, freeze_panes=None)
各参数的类型:
Inferred type: (self: DataFrame, excel_writer: {write_cells}, sheet_name: str, na_rep: str, float_format: Any, columns: Any,
header: bool, index: bool, index_label: Any, startrow: int, startcol: int, engine: Any, merge_cells: bool, encoding: Any,
inf_rep: str, verbose: bool, freeze_panes: Any) -> None
网友评论