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 相关文章推荐
在Python3中使用asyncio库进行快速数据抓取的教程
Apr 02 Python
理解Python中的类与实例
Apr 27 Python
基于Python和Scikit-Learn的机器学习探索
Oct 16 Python
Python使用matplotlib简单绘图示例
Feb 01 Python
在Python中如何传递任意数量的实参的示例代码
Mar 21 Python
Python实现病毒仿真器的方法示例(附demo)
Feb 19 Python
详解在Python中使用Torchmoji将文本转换为表情符号
Jul 27 Python
django使用graphql的实例
Sep 02 Python
python 实现围棋游戏(纯tkinter gui)
Nov 13 Python
pycharm 关闭search everywhere的解决操作
Jan 15 Python
opencv用VS2013调试时用Image Watch插件查看图片
Jul 26 Python
python开发人人对战的五子棋小游戏
May 02 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简单提示框alert封装函数
2010/08/08 PHP
php使用json_encode对变量json编码
2014/04/07 PHP
Laravel学习教程之IOC容器的介绍与用例
2017/08/15 PHP
php使用yield对性能提升的测试实例分析
2019/09/19 PHP
javascript 使用 NodeList需要注意的问题
2013/03/04 Javascript
用javascript将数据导入Excel示例代码
2014/09/10 Javascript
基于zepto.js实现仿手机QQ空间的大图查看组件ImageView.js详解
2015/03/05 Javascript
jQuery无刷新切换主题皮肤实例讲解
2015/10/21 Javascript
jquery拖动层效果插件用法实例分析(附demo源码)
2016/04/28 Javascript
JS数组操作(数组增加、删除、翻转、转字符串、取索引、截取(切片)slice、剪接splice、数组合并)
2016/05/20 Javascript
常用js,css文件统一加载方法(推荐) 并在加载之后调用回调函数
2016/09/23 Javascript
原生js实现手风琴功能(支持横纵向调用)
2017/01/13 Javascript
ES6学习之变量的两种命名方法示例
2017/07/18 Javascript
nodejs 简单实现动态html的方法
2018/05/12 NodeJs
vue生命周期实例小结
2018/08/15 Javascript
webuploader分片上传的实现代码(前后端分离)
2018/09/10 Javascript
分享5个顶级的JavaScript Ajax组件库
2018/09/16 Javascript
Javascript异步编程async实现过程详解
2020/04/02 Javascript
vue 实现根据data中的属性值来设置不同的样式
2020/08/04 Javascript
JavaScript实现浏览器网页自动滚动并点击的示例代码
2020/12/05 Javascript
Python查看多台服务器进程的脚本分享
2014/06/11 Python
Python中文分词工具之结巴分词用法实例总结【经典案例】
2017/04/15 Python
python实现ID3决策树算法
2018/08/29 Python
Pycharm创建项目时如何自动添加头部信息
2019/11/14 Python
tensorflow没有output结点,存储成pb文件的例子
2020/01/04 Python
使用CSS3实现SVG路径描边动画效果入门教程
2019/10/21 HTML / CSS
amazeui页面校验功能的实现代码
2020/08/24 HTML / CSS
Sneaker Studio乌克兰:购买运动鞋
2018/03/26 全球购物
什么是servlet
2012/05/08 面试题
房地产员工找工作的自我评价
2013/11/15 职场文书
大学生全国两会报告感想
2014/03/17 职场文书
个人授权委托书模板
2014/09/14 职场文书
初中生思想道德自我评价
2015/03/09 职场文书
小学生勤俭节约倡议书
2015/04/29 职场文书
企业工会工作总结2015
2015/05/13 职场文书
借条格式范本
2015/05/25 职场文书