-
Notifications
You must be signed in to change notification settings - Fork 0
/
manipulate.py
58 lines (45 loc) · 1.67 KB
/
manipulate.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import csv
from rich import print
def us_reader():
with open("data.csv", "r") as file:
reader = csv.reader(file)
for _ in reader:
print(_)
# print(_[1])
print("----------------------------")
def dic_reader():
with open("data.csv", "r") as file:
reader = csv.DictReader(file)
scratch, c, python = 0, 0, 0
for row in reader:
choise = (row["language"])
if choise.lower() == "python": python += 1
elif choise.lower() == "scratch": scratch += 1
elif choise.lower() == "c": c += 1
print(f"Scratch: {scratch}\nPython: {python}\nC: {c}")
def rnd_w_dict(search):
"""
Reading data from csv file and doing some analytics on
the fetched data.
"""
with open("data.csv", "r") as file:
# Reading csv file's data into a dictionary
reader = csv.DictReader(file)
counts = {}
for row in reader:
if search not in row: # If search isn't in our data
print("Error: Search is out of data")
return
# Calculating occourance of all items in searched field.
choise = (row[search])
if choise in counts:
counts[choise] += 1
else:
counts[choise] = 1
# Printing the searched results of items in searched field.
for value in sorted(counts, key=lambda
option: counts[option],
reverse=True):
print(f"{value}: {counts[value]}")
rnd_w_dict(input("What you wanna search about? "))
# dic_reader()