File tree 2 files changed +27
-10
lines changed
2 files changed +27
-10
lines changed Original file line number Diff line number Diff line change
1
+ name,addresses
2
+ Noura,Street 1/House 1
3
+ Mahmoud,Street 1/House 2
4
+ Nizar,Street 1/House 3
5
+ Raneem,Street 1/House 4
6
+ Omer,Street 1/House 5
7
+ Mark,Street 1/House 6
8
+ John,Street 1/House 7
9
+ Tim,Street 1/House 8
10
+ Sara,Street 1/House 9
11
+ Rob,Street 1/House 10
12
+ Keanu,Street 1/House 11
Original file line number Diff line number Diff line change @@ -6,22 +6,27 @@ def read_using_DictReader(path):
6
6
with open (path , mode = 'r' ) as file :
7
7
# reading the CSV file
8
8
csvFile = csv .DictReader (file )
9
-
9
+ main_dic = []
10
10
# displaying the contents of the CSV file
11
11
for lines in csvFile :
12
- return lines
12
+ main_dic .append (lines )
13
+ return main_dic
13
14
14
- def read_by_pandas_head ():
15
- data = pd .read_csv ('CSV_files/assets/addresses.csv' )
15
+ #retrun the top 5 rows in CSV file
16
+ def read_by_pandas_head (path ):
17
+ data = pd .read_csv (path )
16
18
return data .head ()
17
19
18
- def read_by_pandas_tail ():
19
- data = pd .read_csv ('CSV_files/assets/addresses.csv' )
20
+
21
+ #retrun the bottom 5 rows in CSV file
22
+ def read_by_pandas_tail (path ):
23
+ data = pd .read_csv (path )
20
24
return data .tail ()
21
25
22
26
if __name__ == "__main__" :
23
- print (read_using_DictReader ('assets/addresses.csv' ))
24
- print (read_using_DictReader ())
25
- print (read_by_pandas_head ())
26
- print (read_by_pandas_tail ())
27
+
28
+ path = './assets/addresses.csv'
29
+ print (read_using_DictReader (path ))
30
+ print (read_by_pandas_head (path ))
31
+ print (read_by_pandas_tail (path ))
27
32
You can’t perform that action at this time.
0 commit comments