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