Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CSV_files/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Reading and Writing a CSV File
There are various ways to read a CSV file that uses either the CSV module or the pandas library.

- 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.

- 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.

* **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.


6 changes: 6 additions & 0 deletions CSV_files/assets/addresses.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
John,Doe,120 jefferson st.,Riverside, NJ, 08075
Jack,McGinnis,220 hobo Av.,Phila, PA,09119
"John ""Da Man""",Repici,120 Jefferson St.,Riverside, NJ,08075
Stephen,Tyler,"7452 Terrace ""At the Plaza"" road",SomeTown,SD, 91234
,Blankman,,SomeTown, SD, 00298
"Joan ""the bone"", Anne",Jet,"9th, at Terrace plc",Desert City,CO,00123
17 changes: 17 additions & 0 deletions CSV_files/read_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import csv

def read_using_DictReader():
# opening the CSV file
with open('CSV_files/assets/addresses.csv', mode ='r') as file:
# reading the CSV file
csvFile = csv.DictReader(file)

# displaying the contents of the CSV file
for lines in csvFile:
return lines




if __name__=="__main__":
print(read_using_DictReader())