-
Notifications
You must be signed in to change notification settings - Fork 1
/
describe.py
70 lines (61 loc) · 2.34 KB
/
describe.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
59
60
61
62
63
64
65
66
67
68
69
70
# **************************************************************************** #
# #
# ::: :::::::: #
# describe.py :+: :+: :+: #
# +:+ +:+ +:+ #
# By: obelouch <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/11/23 09:41:24 by obelouch #+# #+# #
# Updated: 2020/12/18 23:57:33 by obelouch ### ########.fr #
# #
# **************************************************************************** #
from src.description import get_description, print_describe
from mylib.csvTools import get_df_from_csv
from mylib.consts import bcolors, errors
from os import path
import sys
def exit_usage(error):
'''
Print the error Msg and Exit
'''
print(f'\n{bcolors.FAIL}Error{bcolors.ENDC}: ', end='')
if error == errors.ARG_NBR:
print('Wrong number of arguments!')
elif error == errors.NO_ARG:
print('No file is provided!')
elif error == errors.NOT_FILE:
print('File not found!')
elif error == errors.NOT_CSV:
print('Wrong file extension, accept only CSV!')
else:
print('Can\'t read the file!')
print(f'{bcolors.WARNING}Usage{bcolors.ENDC}: ', end='')
print('python3 describe.py <_dataset.csv_>')
exit(1)
def get_filename():
'''
Take and check the dataset file from the argument
'''
if len(sys.argv) > 2:
exit_usage(errors.ARG_NBR)
if len(sys.argv) == 1:
exit_usage(errors.NO_ARG)
filename = sys.argv[1]
if not path.isfile(filename):
exit_usage(errors.NOT_FILE)
if not filename.endswith('.csv'):
exit_usage(errors.NOT_CSV)
return filename
def describe():
'''
The Describe Program
'''
csvFile = get_filename()
df = get_df_from_csv(
csvFile,
usecols=[6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],
)
description = get_description(df)
print_describe(description)
# Launch the program
describe()