This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| df.columns = df.iloc[0] | |
| df = df.iloc[1:-1, :-1] | |
| sf_data = df | |
| sf_data.head() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| response = requests.get("http://www.healthysf.org/bdi/outcomes/zipmap.htm") | |
| soup = BeautifulSoup(response.text, "lxml") | |
| table = soup.find_all("table") | |
| df = pd.read_html(str(table)) | |
| df = pd.DataFrame(df[4]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests # library to handle requests | |
| from bs4 import BeautifulSoup | |
| import pandas as pd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| names = [name for name in names if len(name) > 1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| def grey_color_func(word, font_size, position, orientation, random_state=None, | |
| **kwargs): | |
| return "hsl(0, 0%%, %d%%)" % random.randint(60, 100) | |
| plt.figure(figsize=(15,8)) | |
| plt.imshow(wordcloud.recolor(color_func=grey_color_func, random_state=3), interpolation='bilinear') | |
| plt.axis("off") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| unique_string=(" ").join(names) | |
| wordcloud = WordCloud(width = 1000, height = 500).generate(unique_string) | |
| plt.figure(figsize=(15,8)) | |
| plt.imshow(wordcloud, interpolation='bilinear') | |
| plt.axis("off") | |
| plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pip install wordcloud | |
| import numpy as np | |
| from os import path | |
| from PIL import Image | |
| from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator | |
| import matplotlib.pyplot as plt | |
| % matplotlib inline |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from nltk.probability import FreqDist | |
| fdist = FreqDist(names).most_common(20) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| names = [name for name in names if name not in a] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from nltk import word_tokenize | |
| import nltk | |
| nltk.download('stopwords') | |
| from nltk.corpus import stopwords | |
| a = set(stopwords.words('english')) |