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
34 lines (25 loc) · 787 Bytes
/
Copy pathread_csv.py
File metadata and controls
34 lines (25 loc) · 787 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
27
28
29
30
31
32
33
34
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)
main_dic = []
# displaying the contents of the CSV file
for lines in csvFile:
main_dic.append(lines)
return main_dic
# return the top 5 rows in CSV file
def read_by_pandas_head(path):
data = pd.read_csv(path)
return data.head()
# return the bottom 5 rows in CSV file
def read_by_pandas_tail(path):
data = pd.read_csv(path)
return data.tail()
if __name__ == "__main__":
path = './assets/addresses.csv'
print(read_using_DictReader(path))
print(read_by_pandas_head(path))
print(read_by_pandas_tail(path))