您的位置:首页 > 编程语言 > Python开发

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

2017-06-18 21:11 489 查看
上图



代码

# -*- 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?

create a new dataframe object
use .reindex([...]) attribute/method
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: