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

时间:2022-11-22 22:38:49

上图

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

代码

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

How to move one row to the first in pandas?

?
1
2
create a new dataframe object
use .reindex([...]) attribute/method

以上这篇利用pandas将numpy数组导出生成excel的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/qq_33039859/article/details/73440782