current position:Home>06python learning notes - reading external text data

06python learning notes - reading external text data

2022-02-01 09:40:54 User 4576177752001

「 This is my participation 11 The fourth of the yuegengwen challenge 6 God , Check out the activity details :2021 One last more challenge 」.

If needed Python Read txt or csv Formatted data , have access to pandas Module read_table Function or read_csv function . there “ or ” It does not mean that each function intelligently reads data in one format , Second, these two types of Kazakhstan numbers can read the data of text files . Because these two functions are similar in function and parameter use , Therefore, the royal guards here read_table Function as an example , Introduce the usage of this function and the meaning of several important parameters .

filepath_or_buffer: Appoint txt File or csv The specific path of the file .

sep: Specifies the separator between fields in the original dataset , The default is Tab tabs .

header: Whether to use the first row in the original dataset as the header , The first row is used as the field name by default .

names: If there are no fields in the original dataset , You can add a specific header to the data frame when reading data by changing parameters . index_col: Specify some columns in the original dataset as the index of the data frame ( label ).

usecols: Specify which metadata in the set needs to be read .

dtype: When reading data , You can set different data types for each field of the original dataset .

converters: In dictionary format , Set conversion functions for some fields in the dataset .

skiprows: When reading data , Specify the number of rows that need to skip the beginning of the original dataset .

skipfooter: When reading data , Specify the number of rows that need to skip the end of the original dataset .

nrows: Specify the number of rows to read data .

na_values: Specify which feature values in the original dataset are missing values .

skip_blank_lines: Whether to skip the blank line in the original data set when reading data , The default is True.

parse_dates: If the parameter value is True, Then try to parse the row index of the data frame ; If the parameter is a list, try to parse the corresponding date column ; If the parameter is a nested list , Then merge some columns into date Columns ; If the parameter is Dictionary , Then the corresponding column ( The value in the dictionary ), And generate a new field name ( The key in the dictionary ).

thousands: Specifies the millennial character in the original dataset .

comment: Specifies the annotator , While reading the data , If you encounter the annotation specified at the beginning of the line , Then skip this line .

encoding: If there is Chinese in the document , Sometimes you need to specify character encoding .

copyright notice
author[User 4576177752001],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/02/202202010940518605.html

Random recommended