Python read csv file
CSV File
A csv stands for "comma separated values", which is defined as a simple file format that uses specific structuring to arrange tabular data. It stores tabular data such as spreadsheet or database in plain text and has a common format for data interchange. A csv file opens into the excel sheet, and the rows and columns data define the standard format.
Python CSV Module Functions
The CSV module work is used to handle the CSV files to read/write and get data from specified columns. There are different types of CSV functions, which are as follows:
- csv.field_size_limit - It returns the current maximum field size allowed by the parser.
- csv.get_dialect - It returns the dialect associated with a name.
- csv.list_dialects - It returns the names of all registered dialects.
- csv.reader - It read the data from a csv file
- csv.register_dialect - It associates dialect with a name. The name must be a string or a Unicode object.
- csv.writer - It writes the data to a csv file
- o csv.unregister_dialect - It deletes the dialect which is associated with the name from the dialect registry. If a name is not a registered dialect name, then an error is being raised.
- csv.QUOTE_ALL - It instructs the writer objects to quote all fields. csv.QUOTE_MINIMAL - It instructs the writer objects to quote only those fields which contain special characters such as quotechar, delimiter, etc.
- csv.QUOTE_NONNUMERIC - It instructs the writer objects to quote all the non-numeric fields.
- csv.QUOTE_NONE - It instructs the writer object never to quote the fields.
Reading CSV files
Python provides various functions to read csv file. We are describing few method of reading function.
- Using csv.reader() function
In Python, the csv.reader() module is used to read the csv file. It takes each row of the file and makes a list of all the columns.
0 Comments