forked from larymak/Python-project-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_csv.py
More file actions
27 lines (21 loc) · 716 Bytes
/
Copy pathread_csv.py
File metadata and controls
27 lines (21 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import csv
import pandas as pd
def read_using_DictReader(path):
# opening the CSV file
with open(path, 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
def read_by_pandas_head():
data=pd.read_csv('CSV_files/assets/addresses.csv')
return data.head()
def read_by_pandas_tail():
data=pd.read_csv('CSV_files/assets/addresses.csv')
return data.tail()
if __name__=="__main__":
print(read_using_DictReader('assets/addresses.csv'))
print(read_using_DictReader())
print(read_by_pandas_head())
print(read_by_pandas_tail())