You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* There are various ways to read a CSV file that uses either the CSV module or the pandas library.
3
+
4
+
- csv Module: The CSV module is one of the modules in Python which provides classes for reading and writing tabular information in CSV file format.
5
+
6
+
- pandas Library: The pandas library is one of the open-source Python libraries that provide high-performance, convenient data structures and data analysis tools and techniques for Python programming.
7
+
8
+
***Read using csv.DictReader() class:** the CSV file is first opened using the open() method then it is read by using the DictReader class of csv module which works like a regular reader but maps the information in the CSV file into a dictionary. The very first line of the file consists of dictionary keys.
9
+
***Read using pandas module** : you can read cvs file using pandas ,using read_csv method , you can also determine if you want to read the head or the tail or read specific piece of data .
10
+
11
+
12
+
* There are various classes provide by csv module for writting to csv:
13
+
- using csv.writer class
14
+
- using csv.DictWritter class
15
+
16
+
***Write using cvs.DictWritter() class**: this class returns a writer object which maps directories onto output rows.
17
+
18
+
19
+
***Write using pandas module**:You can save your Pandas DataFrame as a CSV file with .to_csv(data)
0 commit comments