-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpandasProva.py
More file actions
31 lines (25 loc) · 947 Bytes
/
pandasProva.py
File metadata and controls
31 lines (25 loc) · 947 Bytes
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
import utility
from resultsVisualization import tree_printer
from databaseConnection import DBConnection
from tabulate import tabulate
from pandas import pandas
from sklearn import tree
connection = DBConnection()
connection.database_connection()
query = "SELECT id, Age, Sex FROM censusdata limit 5"
result = connection.query(query)
print(tabulate(result, tablefmt="fancy_grid"))
# https://pypi.org/project/tabulate/ per info su tabulate
the_frame = pandas.DataFrame.from_dict(result)
print(the_frame)
print(the_frame.dtypes)
"""
print(the_frame.head(2)) #prime righe della table
print(the_frame.tail(2)) #ultime righe della table
print(the_frame.index)
print(the_frame.sort_values(by='Age')) #ordina table per value
"""
classifier = tree.DecisionTreeClassifier()
classifier.fit(the_frame[["id", "Age"]], the_frame["Sex"])
print(classifier)
tree_printer(utility.tree_path, tree, classifier, ["id", "Age"])