Skip to content

update on CSV_files #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2022
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
12 changes: 12 additions & 0 deletions CSV_files/assets/addresses.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name,addresses
Noura,Street 1/House 1
Mahmoud,Street 1/House 2
Nizar,Street 1/House 3
Raneem,Street 1/House 4
Omer,Street 1/House 5
Mark,Street 1/House 6
John,Street 1/House 7
Tim,Street 1/House 8
Sara,Street 1/House 9
Rob,Street 1/House 10
Keanu,Street 1/House 11
25 changes: 15 additions & 10 deletions CSV_files/read_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,27 @@ def read_using_DictReader(path):
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:
return lines
main_dic.append(lines)
return main_dic

def read_by_pandas_head():
data=pd.read_csv('CSV_files/assets/addresses.csv')
#retrun the top 5 rows in CSV file
def read_by_pandas_head(path):
data=pd.read_csv(path)
return data.head()

def read_by_pandas_tail():
data=pd.read_csv('CSV_files/assets/addresses.csv')

#retrun the bottom 5 rows in CSV file
def read_by_pandas_tail(path):
data=pd.read_csv(path)
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())

path='./assets/addresses.csv'
print(read_using_DictReader(path))
print(read_by_pandas_head(path))
print(read_by_pandas_tail(path))