May 30, 2021 Article blog
pd.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)
Description of the parameters:
io: String, the path object of the file
Sheetname: Nonename: String, int, string list, or integer list, default 0, string for sheet name, integer for zero index sheet location, string list or integer list for requesting multiple sheets, get all sheets for None.
sheetname | A description of the value |
---|---|
0 | Get the sheet1 table |
1 | Get the sheet2 table |
‘Sheet3’ | Get the sheet3 table |
[0,1,‘Sheet5’] | Get sheet1, sheet2 and sheet5 tables |
header: represents which row is indexed as a column, with a default of 0 (the first row), and when header is not the first row, all rows before the default column index are deleted and the data is below the column name row;
name: When no header is given in the file, you need to set header to None value and pass in the same number of lists as columns
data = pd.read_excel(r'C:\w3cschool\learn\text\hello_w3cschool.xlsx',header=None,names=np.arange(19))
print(data.head())
index_col: Specifies that it is listed as an index column, and that the default None column (0 index) is used as a row label for DataFrame. \
Skiprows: Skips the line before the specified row, including, to start reading
Any int type whose incoming value starts at 1, beyond the length of the row, is shown as empty, as follows:
Empty DataFrame
Columns: []
Index: []
When the last piece of data is left, it appears as follows:
Empty DataFrame
Columns: [4, peter, 18, man]
Index: []
nrows
The value is the int type, the default Now, takes only the first n rows of data, and passes the arguments by index
When the incoming value is 0, take only the first line, which looks like this:
Empty DataFrame
Columns: [1, jack, 22, man]
Index: []
When the remaining values are passed in, only the rows before that value, including, are displayed, no errors are reported beyond the length of the row, and how many rows are displayed
Note: .csv belongs to the text file, comma separates the file, the encoding is generally gbk;
Description of the parameters:
pd.read_table( r’path’,
sep=’,’,
encoding=‘gbk’,
engine=‘python’).head()
Description of the parameters:
df.to_excel(‘filename.xlsx’)
Description of the parameters:
, no files, paths or objects by default, if not provided, the result will be returned as a string.