-
Notifications
You must be signed in to change notification settings - Fork 0
/
databases1.py
34 lines (29 loc) · 867 Bytes
/
databases1.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
import sqlalchemy as db
import pandas as pd
import matplotlib.pyplot as plt
engine = db.create_engine('mysql+mysqlconnector://root:foobar@localhost:3306/sqlalchemy_mysql')
connection = engine.connect()
query = 'SELECT ViewCount, AnswerCount FROM posts where ViewCount is not NULL'
# result = engine.execute(query).fetchall()
# print(result)
posts_df = pd.read_sql_query(query, engine)
# print(posts_df)
# print('---')
# print(posts_df.columns)
# print('---')
# print(posts_df.dtypes)
# print('---')
# print(posts_df.head())
# print('---')
# print(posts_df[['ViewCount', 'AnswerCount']].max())
# print('---')
# print(posts_df[['ViewCount', 'AnswerCount']].describe())
# print('---')
x = posts_df['AnswerCount']
y = posts_df['ViewCount']
plt.scatter(x, y)
plt.ylim([0, 20])
plt.xlabel('Answers')
plt.ylabel('Views')
plt.title('Posts: Views vs. Answers')
plt.show()