<jupyter_start><jupyter_text>Created by [<NAME>](http://nkelber.com) and Ted Lawless for [JSTOR Labs](https://labs.jstor.org/) under [Creative Commons CC BY License](https://creativecommons.org/licenses/by/4.0/)For questions/comments/improvements, email <EMAIL>.___ Creating a Stopwords List**Description:**This notebook creates a stopwords list and exports it into a CSV file. The following processes are described:* Loading the NLTK stopwords list* Modifying the stopwords list in Python* Saving a stopwords list to a .csv file* Loading a stopwords list from a .csv file**Use Case:** For Researchers (Mostly code without explanation, not ideal for learners)[Take me to the **Learning Version** of this notebook ->](./creating-stopwords-list.ipynb)**Difficulty:** Intermediate**Completion time:** 5 minutes**Knowledge Required:** * Python Basics Series ([Start Python Basics I](./python-basics-1.ipynb))**Knowledge Recommended:** None**Data Format:** CSV files**Libraries Used:*** **[nltk](https://docs.constellate.org/key-terms/nltk)** to create an initial stopwords list* **csv** to read and write the stopwords to a file**Research Pipeline:** None___  Create a Basic Stopwords List<jupyter_code># Start from NLTK #
import nltk
from nltk.corpus import stopwords # Import stopwords from nltk.corpus
stop_words = stopwords.words('english') # Create a list `stop_words` that contains the English stop words list
# Start from Gensim. Creates a list from a frozen set. 
import gensim
from gensim.parsing.preprocessing import STOPWORDS

stop_words = list(STOPWORDS)
# Start from spaCy. 
import spacy
sp = spacy.load('en_core_web_sm')

stop_words = sp.Defaults.stop_words<jupyter_output><empty_output><jupyter_text>Output `stop_words` to CSV File<jupyter_code># Output stop_words to a CSV file

import csv # Import the csv module to work with csv files
with open('data/stop_words.csv', 'w', newline='') as f:
    writer = csv.writer(f)
    writer.writerow(stop_words)<jupyter_output><empty_output><jupyter_text>To Read in the Stopwords CSV<jupyter_code># Open the CSV file and list the contents

with open('data/stop_words.csv', 'r') as f:
    stop_words = f.read().strip().split(",")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11402714932126697, 'fraction_numerical': 0.0018099547511312218, 'mean_word_length': 5.845201238390093, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '278577', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 707, 'n_tokens_neox': 671, 'n_words': 231, 'path': 'creating-stopwords-list-for-research.ipynb', 'repo_name': 'melinduhh/constellate-workshop', 'size': '2234'}