python写入excel

安装模块

pip3 install numpy
pip3 install pandas
pip3 install openpyxl

示例

import numpy as np
import pandas as pd
import openpyxl


df = pd.DataFrame({"id":[1001,1002,1003,1004,1005,1006],
                    "date":pd.date_range('20130102', periods=6),
					"city":['Beijing ', 'SH', ' guangzhou ', 'Shenzhen', 'shanghai', 'BEIJING '],
                   "age":[23,44,54,32,34,32],
                   "category":['100-A','100-B','110-A','110-C','210-A','130-F'],
                   "price":[1200,np.nan,2133,5433,np.nan,4432]},
					columns =['id','date','city','category','age','price'])

#查看数据表的维度
# print(df.shape)

#数据表信息
# print(df.info())

#查看数据表各列格式
# print(df.dtypes)

#查看单列格式
# print(df['city'].dtype)

#查看前3行数据
# print(df.head(3))

#输出到Excel格式
df.to_excel('Excel_to_Python.xlsx', sheet_name='bluewhale_cc')
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页