In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-10-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail the sample analysis of reading and saving pandas files. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
1. Reading Excel files (read_excel) 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)
Parameter description:
Io: string, path object of the file
Sheetname:None, string, int, string list or integer list, default is 0, string is used for worksheet name, integer is used for zero index worksheet location, string list or integer list is used to request multiple worksheets, and get all worksheets when None.
Description of sheetname value 0 get sheet1 form 1 get sheet2 form 'Sheet3' get sheet3 form [0Magne1Magne sheet 5'] get sheet1,sheet2 and sheet5 form
Header: indicates which row is used as the column index. The default is 0 (the first row). When header is not the first row, all rows before the column index are deleted and unread, and the data is the data below the column name. If the data does not contain the column name, set header = None.
Names: when no header is given in the file, you need to set header to the None value and pass in the same number of list as the column
Data = pd.read_excel (ritual C:\ w3cschool\ learn\ text\ hello_w3cschool.xlsx',header=None,names=np.arange (19)) print (data.head ())
Index_col: specifies the column index column, and the default None column (0 index) is used as the row label for DataFrame. \
Skiprows: the line before the specified line (including) is skipped to start reading
For any int type with a value starting from 1, no error is reported beyond the length of the row, which is displayed as blank, as follows:
Empty DataFrame
Columns: []
Index: []
When there is only one piece of data left, it is displayed as follows:
Empty DataFrame
Columns: [4, peter, 18, man]
Index: []
Nrows
The value is int. The default is None. Only the first n rows of data are taken, and parameters are passed by index.
When the input value is 0, only the first row is taken, which is displayed as follows:
Empty DataFrame
Columns: [1, jack, 22, man]
Index: []
When passing in the rest of the value, only the rows before the value (including) are displayed. After exceeding the length of the trip, no error is reported, and how many lines show how many lines.
2. Read csv file (read_csv)
Note: .csv is a text file, comma-separated file, generally encoded as gbk
Parameter description:
Sep: the delimiter between elements. The default delimiter for csv files is comma.
Engine: {'clocked,' python'}. The underlying compilation method is c by default. If you encounter problems, you can change engine to Python.
Encoding: usually gbk
Delimiter: str, default None, delimiter, alternate delimiter (if this parameter is specified, the sep parameter is invalid)
Pd.read_table (ritual path')
Sep=','
Encoding='gbk'
Engine='python') .head ()
3. Save the file (1) Save to excel file: to_excel
Parameter description:
Excel_writer: string or Excelwrite object, file path, or existing ExcelWriter
Sheet_name: string, default 'Sheet1'
Na_rep: string, default'', missing data representation
Df.to_excel ('filename.xlsx')
(2) Save to csv file: to_csv
Parameter description:
Path_or_buf: the default value is None, string or file handle. There are no files, paths or objects by default. If not provided, the result will be returned as a string.
Sep: the delimiter of the field in the output file. Default is','.
Na_rep: missing data representation. Default is''.
There are no files, paths, or objects by default, and if not provided, the result will be returned as a string.
Sep: the delimiter of the field in the output file. Default is','.
Na_rep: missing data representation. Default is''.
This is the end of this article on "sample analysis of reading and saving pandas files". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.