Pandas:Excel操作

一、读取Excel

def read_excel(io,
               sheet_name=0, header=0, names=None,
               index_col=None, usecols=None, squeeze=False,
               dtype=None, engine=None, converters=None,
               true_values=None, false_values=None, skiprows=None,
               nrows=None, na_values=None, parse_dates=False,
               date_parser=None, thousands=None, comment=None,
               skipfooter=0,convert_float=True, **kwds):
  • io : string, path object ; excel 路径。
  • sheetname : string, int, mixed list of strings/ints, or None, default 0 返回多表使用sheetname=[0,1],若sheetname=None是返回全表 注意:int/string 返回的是dataframe,而none和list返回的是dict of dataframe,实际上是tuple的列表
  • header : int, list of ints, default 0 指定列名行,默认0,即取第一行,数据为列名行以下的数据 若数据不含列名,则设定 header = None
  • skiprows : list-like,Rows to skip at the beginning,省略指定行数的数据,1代表数据的第一行,0是行名
  • skip_footer : int,default 0, 省略从尾部数的int行数据
  • index_col : int, list of ints, default None指定列为索引列,也可以使用u”strings”
  • names: 指定一行列名的名字。

二、写入Excel

def to_excel(self, excel_writer, sheet_name='Sheet1', na_rep='',
                 float_format=None, columns=None, header=True, index=True,
                 index_label=None, startrow=0, startcol=0, engine=None,
                 merge_cells=True, encoding=None, inf_rep='inf', verbose=True)
  • excel_writer : string or ExcelWriter object File path or existing ExcelWriter目标路径
  • sheet_name : string, default ‘Sheet1’ Name of sheet which will contain DataFrame,填充excel的第几页
  • na_rep : string, default ”,Missing data representation 缺失值填充
  • columns : sequence, optional,Columns to write 选择输出的的列。
  • header : boolean or list of string, default True Write out column names. If a list of string is given it is assumed to be aliases for the column names
  • index : boolean, default True,Write row names (index)
  • index_label : string or sequence, default None, Column label for index column(s) if desired. If None is given, andheader and index are True, then the index names are used. A sequence should be given if the DataFrame uses MultiIndex.
  • startrow :upper left cell row to dump data frame
  • startcol :upper left cell column to dump data frame
  • engine : string, default None ,write engine to use - you can also set this via the options,io.excel.xlsx.writer, io.excel.xls.writer, andio.excel.xlsm.writer.
  • merge_cells : boolean, default True Write MultiIndex and Hierarchical Rows as merged cells.
  • encoding: string, default None encoding of the resulting excel file. Only necessary for xlwt,other writers support unicode natively.
  • inf_rep : string, default ‘inf’ Representation for infinity (there is no native representation for infinity in Excel)
  • freeze_panes : tuple of integer (length 2), default None Specifies the one-based bottommost row and rightmost column that is to be frozen

猜你喜欢

转载自blog.csdn.net/weixin_42231070/article/details/83418413