Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,4 @@ SR No | Project | Author
101 | [Whatsapp Bot](https://github.com/Python-World/python-mini-projects/tree/master/projects/whatsapp_Bot)| [urmil89](https://github.com/urmil89)
102 | [Zip Bruter](https://github.com/Python-World/python-mini-projects/tree/master/projects/Zip_Bruter) | [Erdoğan YOKSUL](https://www.github.com/eredotpkfr)
103 | [CountDown Timer](https://github.com/Python-World/python-mini-projects/tree/master/projects/Countdown_timer) | [Japneet Kalra](https://github.com/japneetsingh035)
104 | [Work with CSV](https://github.com/Python-World/python-mini-projects/tree/master/projects/work-with-csv) | [Andras Nagy](https://github.com/NAndras95)
9 changes: 9 additions & 0 deletions projects/work-with-csv/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Work with CSV

### Description
This python script read data from csv file and print it, get the rows number, get the smallest and the biggest number in a column.

### Usage
```
python work-with-csv.py
```
11 changes: 11 additions & 0 deletions projects/work-with-csv/data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
1;pfsense.local;192.168.1.1;freebsd
2;proxmox-1.local;192.168.1.11;debian
2;proxmox-2.local;192.168.1.12;debian
2;proxmox-3.local;192.168.1.13;debian
3;mysql57-master.local;192.168.1.100;debian
4;mysql57-slave.local;192.168.1.101;debian
3;nginx-proxy.local;192.168.1.10;debian
3;windows-ad-dns.local;192.168.1.2;windows
3;windows-mssql.local;192.168.1.102;windows
2;webserver.local;192.168.1.111;debian
5;ansible.local;192.168.1.103;centos
43 changes: 43 additions & 0 deletions projects/work-with-csv/work-with-csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import csv

filename = "data.csv" # on windows you may have to use this format: "C:\\Users\<username>\<git_reponame>\work-with-csv\data.csv"
# csv content
# priority;name;ip;os

def list_all_item():
print("1. get all data:")
with open(filename, "r") as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for lines in csv_reader:
print(lines)
print("\n")

def sum_the_rows():
print("2. count the rows")
input_file = open(filename,"r+")
reader_file = csv.reader(input_file)
value = len(list(reader_file))

print(f'Row count {value}')
print("\n")

def get_priority_min_max():
print("3. list the minimum and the maximum priority number")
with open(filename, "r") as csvfile:
data = csv.reader(csvfile, delimiter=';')
minVal, maxVal = [], []
for i in data:
minVal.append(i[0])
maxVal.append(i[0])

print(f'Row min {min(minVal)}')
print(f'Row max {max(maxVal)}')
print("\n")

def main():
list_all_item()
sum_the_rows()
get_priority_min_max()

if __name__ == "__main__":
main()