-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_wordcloud.py
36 lines (29 loc) · 966 Bytes
/
create_wordcloud.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
# Load Packages
import pandas as pd
from sqlalchemy import create_engine
from wordcloud import WordCloud
def load_data(database_filepath):
"""
Load data from SQL database to use for modelling
INPUTS:
database_filepath: filepath of the database
OUTPUTS:
X: dataframe of explanatory variables
y: dataframe of dependant variables
category_names: names of the categories of the dependant variables
"""
# load data from database
engine = create_engine('sqlite:///'+database_filepath)
df = pd.read_sql_table('DisasterMessages',engine)
X = df.message
y = df.iloc[:,4:]
category_names=y.columns
#X = X.head(1000)
#y = y.head(1000)
return X, y, category_names
# Load data
X,y,category_names = load_data("data/DisasterResponse.db")
# Generate Wordcloud
wordcloud = WordCloud(width=1000,height=400).generate(' '.join(X))
# Generate plot
wordcloud.to_file("/app/static/wordcloud.png")