利用pandas将numpy数组导出生成excel

 

代码

 1 # -*- coding: utf-8 -*-
 2 """
 3 Created on Sun Jun 18 20:57:34 2017
 4 
 5 @author: Bruce Lau
 6 """
 7 
 8 import numpy as np
 9 import pandas as pd
10 
11 # prepare for data
12 data = np.arange(1,101).reshape((10,10))
13 data_df = pd.DataFrame(data)
14 
15 # change the index and column name
16 data_df.columns = ['A','B','C','D','E','F','G','H','I','J']
17 data_df.index = ['a','b','c','d','e','f','g','h','i','j']
18 
19 # create and writer pd.DataFrame to excel
20 writer = pd.ExcelWriter('Save_Excel.xlsx')
21 data_df.to_excel(writer,'page_1',float_format='%.5f') # float_format 控制精度
22 writer.save()

 转载:https://blog.csdn.net/qq_33039859/article/details/73440782

posted on 2018-04-18 23:10  NothingLZ  阅读(7510)  评论(0编辑  收藏  举报

导航