Python 中pandas.read_excel详细介绍


Posted in Python onJune 23, 2017

Python 中pandas.read_excel详细介绍

#coding:utf-8
import pandas as pd
import numpy as np

filefullpath = r"/home/geeklee/temp/all_gov_file/pol_gov_mon/downloads/1.xls"
#filefullpath = r"/home/geeklee/temp/all_gov_file/pol_gov_mon/downloads/26368f3a-ea03-46b9-8033-73615ed07816.xls"
df = pd.read_excel(filefullpath,skiprows=[0])
#df = pd.read_excel(filefullpath, sheetname=[0,2],skiprows=[0])
#sheetname指定为读取几个sheet,sheet数目从0开始
#如果sheetname=[0,2],那代表读取第0页和第2页的sheet
#skiprows=[0]代表读取跳过的行数第0行,不写代表不跳过标题
#df = pd.read_excel(filefullpath, sheetname=None ,skiprows=[0])

print df
print type(df)
#若果有多页,type(df)就为<type 'dict'>
#如果就一页,type(df)就为<class 'pandas.core.frame.DataFrame'>
#{0:dataframe,1:dataframe,2:dataframe}
pandas.read_excel(io, sheetname=0, header=0, skiprows=None, skip_footer=0,
 index_col=None, names=None, parse_cols=None, parse_dates=False, date_parser=None,
 na_values=None, thousands=None, convert_float=True, has_index_names=None, converters=None,
 engine=None, squeeze=False, **kwds)

Read an Excel table into a pandas DataFrame

参数解析:

io : string, path object (pathlib.Path or py._path.local.LocalPath),

  file-like object, pandas ExcelFile, or xlrd workbook. The string could be a URL. Valid URL schemes include http, ftp, s3, and file. For file URLs, a host is expected. For instance, a local file could be file://localhost/path/to/workbook.xlsx

sheetname : string, int, mixed list of strings/ints, or None, default 0

  Strings are used for sheet names, Integers are used in zero-indexed sheet positions.

  Lists of strings/integers are used to request multiple sheets.

  Specify None to get all sheets.

  str|int -> DataFrame is returned. list|None -> Dict of DataFrames is returned, with keys representing sheets.

  Available Cases

    Defaults to 0 -> 1st sheet as a DataFrame
    1 -> 2nd sheet as a DataFrame
    “Sheet1” -> 1st sheet as a DataFrame
    [0,1,”Sheet5”] -> 1st, 2nd & 5th sheet as a dictionary of DataFrames
    None -> All sheets as a dictionary of DataFrames

header : int, list of ints, default 0

  Row (0-indexed) to use for the column labels of the parsed DataFrame. If a list of integers is passed those row positions will be combined into a MultiIndex

skiprows : list-like

  Rows to skip at the beginning (0-indexed)

skip_footer : int, default 0

  Rows at the end to skip (0-indexed)

index_col : int, list of ints, default None

  Column (0-indexed) to use as the row labels of the DataFrame. Pass None if there is no such column. If a list is passed, those columns will be combined into a MultiIndex

names : array-like, default None

  List of column names to use. If file contains no header row, then you should explicitly pass header=None

converters : dict, default None

  Dict of functions for converting values in certain columns. Keys can either be integers or column labels, values are functions that take one input argument, the Excel cell content, and return the transformed content.

parse_cols : int or list, default None

    If None then parse all columns,
    If int then indicates last column to be parsed
    If list of ints then indicates list of column numbers to be parsed
    If string then indicates comma separated list of column names and column ranges (e.g. “A:E” or “A,C,E:F”)

squeeze : boolean, default False

  If the parsed data only contains one column then return a Series

na_values : list-like, default None

  List of additional strings to recognize as NA/NaN

thousands : str, default None

  Thousands separator for parsing string columns to numeric. Note that this parameter is only necessary for columns stored as TEXT in Excel, any numeric columns will automatically be parsed, regardless of display format.

keep_default_na : bool, default True

  If na_values are specified and keep_default_na is False the default NaN values are overridden, otherwise they're appended to

verbose : boolean, default False

  Indicate number of NA values placed in non-numeric columns

engine: string, default None

  If io is not a buffer or path, this must be set to identify io. Acceptable values are None or xlrd

convert_float : boolean, default True

  convert integral floats to int (i.e., 1.0 ?> 1). If False, all numeric data will be read in as floats: Excel stores all numbers as floats internally

has_index_names : boolean, default None

  DEPRECATED: for version 0.17+ index names will be automatically inferred based on index_col. To read Excel output from 0.16.2 and prior that had saved index names, use True.

return返回的结果

parsed : DataFrame or Dict of DataFrames

  DataFrame from the passed in Excel file. See notes in sheetname argument for more information on when a Dict of Dataframes is returned.

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

Python 相关文章推荐
Python中SOAP项目的介绍及其在web开发中的应用
Apr 14 Python
Python读写文件方法总结
Jun 09 Python
python 重定向获取真实url的方法
May 11 Python
Tensorflow使用支持向量机拟合线性回归
Sep 07 Python
在IPython中进行Python程序执行时间的测量方法
Nov 01 Python
python简单区块链模拟详解
Jul 03 Python
如何使用django的MTV开发模式返回一个网页
Jul 22 Python
python用线性回归预测股票价格的实现代码
Sep 04 Python
详解Python的三种拷贝方式
Feb 11 Python
Python爬取你好李焕英豆瓣短评生成词云的示例代码
Feb 24 Python
Python包管理工具pip的15 个使用小技巧
May 17 Python
python使用tkinter实现透明窗体上绘制随机出现的小球(实例代码)
May 17 Python
python3.4用函数操作mysql5.7数据库
Jun 23 #Python
Python实现树的先序、中序、后序排序算法示例
Jun 23 #Python
详解python中 os._exit() 和 sys.exit(), exit(0)和exit(1) 的用法和区别
Jun 23 #Python
Python数据操作方法封装类实例
Jun 23 #Python
Python守护线程用法实例
Jun 23 #Python
python使用fcntl模块实现程序加锁功能示例
Jun 23 #Python
Django自定义认证方式用法示例
Jun 23 #Python
You might like
用PHP生成静态HTML速度快类库
2007/03/18 PHP
php include,include_once,require,require_once
2008/09/05 PHP
PHP静态调用非静态方法的应用分析
2013/05/02 PHP
基于MySQL到MongoDB简易对照表的详解
2013/06/03 PHP
深入PHP获取随机数字和字母的方法详解
2013/06/06 PHP
为你总结一些php系统类函数
2015/10/21 PHP
PHP之十六个魔术方法详细介绍
2016/11/01 PHP
PHP实现的mysql主从数据库状态检测功能示例
2017/07/20 PHP
laravel migrate初学常见错误的解决方法
2017/10/11 PHP
jquery 事件对象属性小结
2010/04/27 Javascript
Javascript中call的两种用法实例
2013/12/13 Javascript
jQuery on方法传递参数示例
2014/12/09 Javascript
全面解析Bootstrap中tooltip、popover的使用方法
2016/06/13 Javascript
Bootstrap三种表单布局的使用方法
2016/06/21 Javascript
浅析location.href跨窗口调用函数
2016/11/22 Javascript
jquery实现手机端单店铺购物车结算删除功能
2017/02/22 Javascript
微信小程序显示下拉列表功能【附源码下载】
2017/12/12 Javascript
JavaScript模块管理的简单实现方式详解
2019/06/15 Javascript
VueQuillEditor富文本上传图片(非base64)
2020/06/03 Javascript
使用Vue实现一个树组件的示例
2020/11/06 Javascript
五句话帮你轻松搞定js原型链
2020/12/09 Javascript
9种python web 程序的部署方式小结
2014/06/30 Python
深入理解Python中的元类(metaclass)
2015/02/14 Python
python快速编写单行注释多行注释的方法
2019/07/31 Python
Python Django 前后端分离 API的方法
2019/08/28 Python
python实现的config文件读写功能示例
2019/09/24 Python
pytorch使用 to 进行类型转换方式
2020/01/08 Python
Python中pyecharts安装及安装失败的解决方法
2020/02/18 Python
关于keras.layers.Conv1D的kernel_size参数使用介绍
2020/05/22 Python
法国太阳镜店:Sunglasses Shop
2016/08/27 全球购物
伦敦一家西班牙童装精品店:La Coqueta
2018/02/02 全球购物
员工自我鉴定范文
2013/10/06 职场文书
毕业生简历自我评价范文
2014/04/09 职场文书
竞选纪律委员演讲稿
2014/09/13 职场文书
2015年中秋节活动总结
2015/03/23 职场文书
nginx反向代理配置去除前缀案例教程
2021/07/26 Servers