python中numpy数组保存为Excel文件


# Encoding: utf-8

'''
author: yhwu
version: 2021-04-19
function: numpy array write in the excel file
'''

import numpy as np
import pandas as pd

# define a as the numpy array
a = np.array([1, 2, 3])
# transform a to pandas DataFrame
a_pd = pd.DataFrame(a)
# create writer to write an excel file
writer = pd.ExcelWriter('a.xlsx')
# write in ro file, 'sheet1' is the page title, float_format is the accuracy of data
a_pd.to_excel(writer, 'sheet1', float_format='%.6f')
# save file
writer.save()
# close writer
writer.close()

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM