楼主: c11611
937 1

[新手尝试] 新手第一帖 [推广有奖]

  • 1关注
  • 0粉丝

大专生

0%

还不是VIP/贵宾

-

威望
0
论坛币
1245 个
通用积分
1.7151
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
595 点
帖子
15
精华
0
在线时间
40 小时
注册时间
2017-6-22
最后登录
2024-3-10

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
新手第一贴,端午节快乐.
一、Read an Excel table into a pandas 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,dtype=None, true_values=None, false_values=None, engine=None,squeeze=False, **kwds)




Parameters:




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 befile://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 aMultiIndex


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 aMultiIndex. If a subset of data is selected withparse_cols, index_col is based on the subset.


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.


dtype : Type name or dict of column -> type, default None

Data type for data or columns. E.g. {‘a’: np.float64, ‘b’: np.int32} Use object to preserve data as stored in Excel and not interpret dtype. If converters are specified, they will be applied INSTEAD of dtype conversion.

New in version 0.20.0.



true_values : list, default None

Values to consider as True

New in version 0.19.0.



false_values : list, default None

Values to consider as False

New in version 0.19.0.



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 Excel column letters and column ranges (e.g. “A:E” or “A,C,E:F”). Ranges are inclusive of both sides.

squeeze : boolean, default False

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


na_values : scalar, str, list-like, or dict, default None

Additional strings to recognize as NA/NaN. If dict passed, specific per-column NA values. By default the following values are interpreted as NaN: ‘’, ‘#N/A’, ‘#N/A N/A’, ‘#NA’, ‘-1.#IND’, ‘-1.#QNAN’, ‘-NaN’, ‘-nan’,


‘1.#IND’, ‘1.#QNAN’, ‘N/A’, ‘NA’, ‘NULL’, ‘NaN’, ‘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.






Returns:


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.



  




example:
Import pandas as pd

df=pd.read_excel('path_to_file.xls',sheetname='Sheet1',na_values=['NA']),parse_cols=[0,2,3])

参数说明: 第一个参数为excel路径
                   sheetname为excel中需要读取的表名
                   parse_cols 为需要读的列

2、excel 写入
df.to_excel('path_to_file.xlsx',sheet_name='Sheet1')


3、   select data from  DataFrame



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:端午节

沙发
r9205009 发表于 2018-6-18 21:43:04 |只看作者 |坛友微信交流群
休闲区(12区),欢迎您来本区多发表文章,意见或想法(需依论坛相关规范)或发售有用或稀缺之书籍,信息;赚取论坛币并休闲娱乐一番
关注微信送论坛币    https://bbs.pinggu.org/thread-2192087-1-1.html
推广论坛赚取论坛币 https://bbs.pinggu.org/home.php?mod=spacecp&ac=promotion
多种方式赚取论坛币:https://bbs.pinggu.org/home.php?mod=spacecp&ac=main
会员权限赠送论坛币  https://bbs.pinggu.org/buy.php

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加JingGuanBbs
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-28 10:07