using Yet Another Keyword Extraction tool (YAKE)
By Aigerim Karatay
Installations and importing needed packages:
!pip3 install git+https://github.com/LIAAD/yake
Collecting git+https://github.com/LIAAD/yake Cloning https://github.com/LIAAD/yake to /private/var/folders/j9/8mnxtc295ylfl5xlqvrdbwth0000gn/T/pip-req-build-sszbc16q Running command git clone --filter=blob:none --quiet https://github.com/LIAAD/yake /private/var/folders/j9/8mnxtc295ylfl5xlqvrdbwth0000gn/T/pip-req-build-sszbc16q Resolved https://github.com/LIAAD/yake to commit 374fc1c1c19eb080d5b6115cbb8d4a4324392e54 Preparing metadata (setup.py) ... - \ done Requirement already satisfied: tabulate in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from yake==0.4.8) (0.8.10) Requirement already satisfied: click>=6.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from yake==0.4.8) (8.1.3) Requirement already satisfied: numpy in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from yake==0.4.8) (1.23.2) Requirement already satisfied: segtok in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from yake==0.4.8) (1.5.11) Requirement already satisfied: networkx in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from yake==0.4.8) (2.8.7) Requirement already satisfied: jellyfish in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from yake==0.4.8) (0.9.0) Requirement already satisfied: regex in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from segtok->yake==0.4.8) (2022.9.13) [notice] A new release of pip available: 22.2.1 -> 23.0.1 [notice] To update, run: pip3 install --upgrade pip
import yake
import pandas as pd
!pip3 install nltk
Requirement already satisfied: nltk in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (3.7) Requirement already satisfied: regex>=2021.8.3 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from nltk) (2022.9.13) Requirement already satisfied: click in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from nltk) (8.1.3) Requirement already satisfied: tqdm in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from nltk) (4.64.1) Requirement already satisfied: joblib in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from nltk) (1.2.0) [notice] A new release of pip available: 22.2.1 -> 23.0.1 [notice] To update, run: pip3 install --upgrade pip
!pip3 install spacy
Requirement already satisfied: spacy in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (3.4.1) Requirement already satisfied: spacy-loggers<2.0.0,>=1.0.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy) (1.0.3) Requirement already satisfied: requests<3.0.0,>=2.13.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy) (2.28.1) Requirement already satisfied: jinja2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy) (3.1.2) Requirement already satisfied: pydantic!=1.8,!=1.8.1,<1.10.0,>=1.7.4 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy) (1.9.2) Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy) (1.0.8) Requirement already satisfied: numpy>=1.15.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy) (1.23.2) Requirement already satisfied: pathy>=0.3.5 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy) (0.6.2) Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy) (63.2.0) Requirement already satisfied: srsly<3.0.0,>=2.4.3 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy) (2.4.4) Requirement already satisfied: catalogue<2.1.0,>=2.0.6 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy) (2.0.8) Requirement already satisfied: typer<0.5.0,>=0.3.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy) (0.4.2) Requirement already satisfied: cymem<2.1.0,>=2.0.2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy) (2.0.6) Requirement already satisfied: packaging>=20.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy) (21.3) Requirement already satisfied: thinc<8.2.0,>=8.1.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy) (8.1.2) Requirement already satisfied: spacy-legacy<3.1.0,>=3.0.9 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy) (3.0.10) Requirement already satisfied: wasabi<1.1.0,>=0.9.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy) (0.10.1) Requirement already satisfied: langcodes<4.0.0,>=3.2.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy) (3.3.0) Requirement already satisfied: tqdm<5.0.0,>=4.38.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy) (4.64.1) Requirement already satisfied: preshed<3.1.0,>=3.0.2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy) (3.0.7) Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from packaging>=20.0->spacy) (3.0.9) Requirement already satisfied: smart-open<6.0.0,>=5.2.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from pathy>=0.3.5->spacy) (5.2.1) Requirement already satisfied: typing-extensions>=3.7.4.3 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from pydantic!=1.8,!=1.8.1,<1.10.0,>=1.7.4->spacy) (4.3.0) Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy) (1.26.12) Requirement already satisfied: certifi>=2017.4.17 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy) (2022.6.15) Requirement already satisfied: charset-normalizer<3,>=2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy) (2.1.1) Requirement already satisfied: idna<4,>=2.5 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy) (3.3) Requirement already satisfied: blis<0.8.0,>=0.7.8 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from thinc<8.2.0,>=8.1.0->spacy) (0.7.8) Requirement already satisfied: confection<1.0.0,>=0.0.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from thinc<8.2.0,>=8.1.0->spacy) (0.0.2) Requirement already satisfied: click<9.0.0,>=7.1.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from typer<0.5.0,>=0.3.0->spacy) (8.1.3) Requirement already satisfied: MarkupSafe>=2.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from jinja2->spacy) (2.1.1) [notice] A new release of pip available: 22.2.1 -> 23.0.1 [notice] To update, run: pip3 install --upgrade pip
import re
import string
from bs4 import BeautifulSoup
import nltk
from nltk.stem import PorterStemmer
from nltk.stem.wordnet import WordNetLemmatizer
import spacy
2023-03-31 22:30:36.555338: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Reading the collected articles from csv file:
file_path = "health_articles.csv"
fitness_articles = pd.read_csv(file_path)
fitness_articles.head()
Article Heading | Article Copy | Article Link | |
---|---|---|---|
0 | Recommit To Getting Fit: How To Plan Your Retu... | Living a fitness-based lifestyle can be incred... | https://www.muscleandstrength.com/articles/rec... |
1 | In Training, Consistency is the Key To Your Fi... | Consistency is arguably the most important com... | https://www.nifs.org/blog/in-training-consiste... |
2 | 365 Day Challenge: Be The Best You Can Be | In the fitness game, the most common goals by ... | https://www.muscleandstrength.com/articles/365... |
3 | How To Stay Fit forever: 25 Tips To Keep Movin... | When it comes to exercise, we think about how ... | https://www.theguardian.com/lifeandstyle/2018/... |
4 | How To Get (And Stay) Fit At Any Age | Exercise is the closest thing we have to a mag... | https://www.womenshealthmag.com/uk/fitness/wor... |
from spacy.cli import download
download("en_core_web_sm")
Collecting en-core-web-sm==3.4.1
Downloading https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.4.1/en_core_web_sm-3.4.1-py3-none-any.whl (12.8 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 12.8/12.8 MB 1.8 MB/s eta 0:00:00
Requirement already satisfied: spacy<3.5.0,>=3.4.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from en-core-web-sm==3.4.1) (3.4.1)
Requirement already satisfied: pathy>=0.3.5 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (0.6.2)
Requirement already satisfied: langcodes<4.0.0,>=3.2.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (3.3.0)
Requirement already satisfied: packaging>=20.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (21.3)
Requirement already satisfied: wasabi<1.1.0,>=0.9.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (0.10.1)
Requirement already satisfied: numpy>=1.15.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (1.23.2)
Requirement already satisfied: typer<0.5.0,>=0.3.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (0.4.2)
Requirement already satisfied: cymem<2.1.0,>=2.0.2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (2.0.6)
Requirement already satisfied: thinc<8.2.0,>=8.1.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (8.1.2)
Requirement already satisfied: spacy-loggers<2.0.0,>=1.0.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (1.0.3)
Requirement already satisfied: srsly<3.0.0,>=2.4.3 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (2.4.4)
Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (1.0.8)
Requirement already satisfied: preshed<3.1.0,>=3.0.2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (3.0.7)
Requirement already satisfied: catalogue<2.1.0,>=2.0.6 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (2.0.8)
Requirement already satisfied: requests<3.0.0,>=2.13.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (2.28.1)
Requirement already satisfied: pydantic!=1.8,!=1.8.1,<1.10.0,>=1.7.4 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (1.9.2)
Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (63.2.0)
Requirement already satisfied: jinja2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (3.1.2)
Requirement already satisfied: tqdm<5.0.0,>=4.38.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (4.64.1)
Requirement already satisfied: spacy-legacy<3.1.0,>=3.0.9 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (3.0.10)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from packaging>=20.0->spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (3.0.9)
Requirement already satisfied: smart-open<6.0.0,>=5.2.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from pathy>=0.3.5->spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (5.2.1)
Requirement already satisfied: typing-extensions>=3.7.4.3 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from pydantic!=1.8,!=1.8.1,<1.10.0,>=1.7.4->spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (4.3.0)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (1.26.12)
Requirement already satisfied: certifi>=2017.4.17 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (2022.6.15)
Requirement already satisfied: idna<4,>=2.5 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (3.3)
Requirement already satisfied: charset-normalizer<3,>=2 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from requests<3.0.0,>=2.13.0->spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (2.1.1)
Requirement already satisfied: confection<1.0.0,>=0.0.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from thinc<8.2.0,>=8.1.0->spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (0.0.2)
Requirement already satisfied: blis<0.8.0,>=0.7.8 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from thinc<8.2.0,>=8.1.0->spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (0.7.8)
Requirement already satisfied: click<9.0.0,>=7.1.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from typer<0.5.0,>=0.3.0->spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (8.1.3)
Requirement already satisfied: MarkupSafe>=2.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from jinja2->spacy<3.5.0,>=3.4.0->en-core-web-sm==3.4.1) (2.1.1)
Installing collected packages: en-core-web-sm
Attempting uninstall: en-core-web-sm
Found existing installation: en-core-web-sm 3.4.0
Uninstalling en-core-web-sm-3.4.0:
Successfully uninstalled en-core-web-sm-3.4.0
Successfully installed en-core-web-sm-3.4.1
✔ Download and installation successful
You can now load the package via spacy.load('en_core_web_sm')
[notice] A new release of pip available: 22.2.1 -> 23.0.1 [notice] To update, run: pip3 install --upgrade pip
import nltk.corpus
nltk.download('stopwords')
from nltk.corpus import stopwords
stop = stopwords.words('english')
from nltk.stem.porter import PorterStemmer
from nltk.stem import WordNetLemmatizer
[nltk_data] Error loading stopwords: <urlopen error [SSL: [nltk_data] CERTIFICATE_VERIFY_FAILED] certificate verify failed: [nltk_data] unable to get local issuer certificate (_ssl.c:997)>
# Load spacy
# nlp = spacy.load('en_core_web_sm')
def clean_string(text):
final_string = ""
# Make lower
text = text.lower()
# Removing Unicode Characters
text = re.sub(r"(@\[A-Za-z0-9]+)|([^0-9A-Za-z \t])|(\w+:\/\/\S+)|^rt|http.+?", "", text)
# Removing stopwords
text = " ".join([word for word in text.split() if word not in (stop)])
# nltk_tokens = nltk.word_tokenize(text)
# stemmer = PorterStemmer()
# for token in nltk_tokens:
# token = stemmer.stem(token)
# text = " ".join(nltk_tokens)
# initializing punctuations string
punc = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
# Removing punctuations in string
# Using loop + punctuation string
for ele in text:
if ele in punc:
text = text.replace(ele, "")
final_string = text
return final_string
import nltk
import ssl
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
pass
else:
ssl._create_default_https_context = _create_unverified_https_context
nltk.download()
showing info https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/index.xml
True
fitness_articles['cleaned_text'] = fitness_articles['Article Copy'].apply(lambda x: clean_string(x))
clean_string(fitness_articles['Article Copy'][3])
'comes exercise think get fit often starting problem big problem maintaining says falko sniehotta professor behavioural medicine health psychology newcastle university official uk guidelines say adults strength exercises well 150 minutes moderate activity 75 minutes vigorous activity every week according health survey england 2016 34 men 42 women hitting aerobic exercise targets even 69 77 respectively enough strengthening activity report world health organization last week found people uk among least active world 32 men 40 women reporting inactivity meanwhile obesity adding chronic longterm diseases cited public health englands analysis shows women uk dying earlier eu countries know keep moving motivation slips weather takes turn worse life gets way try 25 pieces advice experts guardian readers keep going reasons beginning exercise fundamental whether keep says michelle segar director university michigans sport health activity research policy center often society promotes exercise fitness hooking shortterm motivation guilt shame evidence says younger people go gym reasons appearancebased past early 20s doesnt fuel motivation much vague future goals help want get fit want lose weight segar author sweat simple science motivation bring lifetime fitness says successful focus immediate positive feelings stress reduction increased energy making friends way going prioritise time exercise going deliver kind benefit truly compelling valuable daily life says danger typical new year resolutions approach fitness says personal trainer matt roberts people jump everything change diet start exercising stop drinking smoking within couple weeks lost motivation got tired havent shape going take time likes trend towards highintensity interval training hiit recommends people include every day intense people twice week combined slow jogs swimming fast walks plus two three rest days least first month give someone chance recovery sessions alongside highintensity workouts helpful try make things actively dislike says segar advises thinking types activities rollerskating bike riding liked child dont feel really enjoy exercise lot people stick exercise say feel better elements probably enjoyable though physical response body feeling getting stronger pleasure comes mastering sportfor many people obvious choices arent necessarily ones would enjoy says sniehotta also director national institute health researchs policy research unit behavioural science need look outside might different sports simple things like sharing activities people individual motivation lack part bigger picture money parenting demands even live stumbling blocks says sniehotta tiredness depression work stress ill family members impact physical activity lot support around find easier maintain physical activity points live certain parts country might comfortable outdoor physical activity others conclude people dont get enough physical activity lacking motivation problematicsegar suggests realistic skip ideal going gym five days week really analytical work familyrelated needs starting set goals big fail youll feel like failure end week always ask clients reflect worked didnt maybe fitting walk lunch worked didnt energy work need willpower something dont really want says segar instead think exercise terms want get physical activity benefit today feel move feel move anything allows exercise ticking goals help says sniehotta provides gratification costs higher instance walking cycling work making friends joining sports club running friend goal spend time countryside running helps thattry combine physical activity something else example workplace dont use lift try reduce email possible walk people says sniehotta course day walk work move lot building actually get 15000 steps try make physical activity hit many meaningful targets take running tiring getting door shoes water bottle route going take points sniehottta longer costs associated activity physical activity regularly planning helps make sustainable behaviour missing sessions doesnt dont time exercise many people working two jobs extensive caring responsibilities undoubtedly true genuinely true might question priorities says sniehotta recommends planning first action planning plan going try stick second type coping planning anticipating things get way putting plan place get motivated segar adds people dont give permission prioritise selfcare behaviours like exercise workout doesnt take hour says roberts wellstructured 15minute workout really effective really pressed time regular longer sessions says tell youre going make time change schedule accordingly rains week dont go running feel guilty combination emotion lack confidence brings us point people fail times think failure entire project says sniehotta remember possible get back trackif previous exercise regimes havent worked dont beat try try something else says tend mindset cant lose weight blame however could change method doesnt work lets try something different chance better prevents blame helpful start lose muscle mass age around 30 says hollie grant personal training pilates instructor owner pilatespt resistance training using body weight pressups equipment resistance bands important says going help keep muscle mass least slow loss needs form aerobic exercise would also recommend people start adding balance challenges balance affected get older 5k runs dont know push faster go rate exertion one 10 says grant see numbers go thats start pushing bit faster roberts says regular exercise seeing progress twoweek period pushing feel getting easier youre looking change speed endurance strength caring responsibilities roberts says lot within small area home living room easy routine might alternate leg exercise arm exercise says called peripheral heart action training six eight exercises effect going upper lower body produces pretty strong metabolism lift cardiovascular workout try squats half pressups lunges tricep dips glute raises youre raising heart rate working muscles good general workout take 1520 minutes require chair tricep dips although dumbbells helpful often told housework gardening contribute weekly exercise targets simple measure really youre getting generally hot breath youre working level conversation somebody youre youre puffing bit says roberts gardening youd heavier gardening digging weeding youre walking dog make genuine exercise session run dog find route includes hills joslyn thompson rule personal trainer says general rule neck headache cold mindful youre feeling generally ok sort exercise neck youre trouble breathing rest key thing sensible planning highintensity workout would take pace sometimes moving make feel better recovering illness says trust instincts dont want go straight back training four times week might want number sessions make shorter fewer clearly quickly start exercising depends type injury seek advice doctor psychologically though says thompson rule even everything still dips road going linear progression getting better says thompson rule listen body doctors advice sixweek postnatal checkup caesarean section getting back exercise slower pregnancyrelated back injuries problems abdominal muscles affect soon get back training may require physiotherapy youre walking bit energy depending women never trained pregnancy starting regime baby quite something undertake says thompson rule patient get emails women asking theyre going get stomachs flat anything relax take care take care baby youre feeling bit energised slowly get back routine recommends starting basic stuff like walking carrying baby sling goaloriented people grant says useful monitor progress closely allow flexibility goals might stressful day work go run quickly think im going bother however start get bit addictive dont listen body youre risk injury winter necessarily time hibernate says thompson rule decisive put trainers door try think colddrizzlegreyness going gym voice head make us feel like hassle youre think procrastinating long'
fitness_articles.head()
Article Heading | Article Copy | Article Link | cleaned_text | |
---|---|---|---|---|
0 | Recommit To Getting Fit: How To Plan Your Retu... | Living a fitness-based lifestyle can be incred... | https://www.muscleandstrength.com/articles/rec... | living fitnessbased lifestyle incredible many ... |
1 | In Training, Consistency is the Key To Your Fi... | Consistency is arguably the most important com... | https://www.nifs.org/blog/in-training-consiste... | consistency arguably important component worki... |
2 | 365 Day Challenge: Be The Best You Can Be | In the fitness game, the most common goals by ... | https://www.muscleandstrength.com/articles/365... | fitness game common goals far lose body fat ge... |
3 | How To Stay Fit forever: 25 Tips To Keep Movin... | When it comes to exercise, we think about how ... | https://www.theguardian.com/lifeandstyle/2018/... | comes exercise think get fit often starting pr... |
4 | How To Get (And Stay) Fit At Any Age | Exercise is the closest thing we have to a mag... | https://www.womenshealthmag.com/uk/fitness/wor... | exercise closest thing magic bullet counter ef... |
def get_keywords(x):
kw_extractor = yake.KeywordExtractor(top=5, stopwords=None, n = 2)
# keywords = kw_extractor.extract_keywords(fitness_articles['cleaned_text'][0])
keywords = kw_extractor.extract_keywords(x)
keyword_list = []
for kw, v in keywords:
# print("Keyphrase: ",kw, ": score", v)
keyword_list.append(kw)
return ", ".join(keyword_list)
fitness_articles['keywords'] = fitness_articles['cleaned_text'].apply(lambda x: get_keywords(x))
fitness_articles.keywords[5]
'weight loss, lose weight, walking weight, strikes ground, daily average'
fitness_articles.head()
Article Heading | Article Copy | Article Link | cleaned_text | keywords | |
---|---|---|---|---|---|
0 | Recommit To Getting Fit: How To Plan Your Retu... | Living a fitness-based lifestyle can be incred... | https://www.muscleandstrength.com/articles/rec... | living fitnessbased lifestyle incredible many ... | nutrition plan, solid nutrition, social media,... |
1 | In Training, Consistency is the Key To Your Fi... | Consistency is arguably the most important com... | https://www.nifs.org/blog/in-training-consiste... | consistency arguably important component worki... | small change, consistent training, weeks depen... |
2 | 365 Day Challenge: Be The Best You Can Be | In the fitness game, the most common goals by ... | https://www.muscleandstrength.com/articles/365... | fitness game common goals far lose body fat ge... | year today, eating correctly, food rule, make ... |
3 | How To Stay Fit forever: 25 Tips To Keep Movin... | When it comes to exercise, we think about how ... | https://www.theguardian.com/lifeandstyle/2018/... | comes exercise think get fit often starting pr... | physical activity, thompson rule, back trainin... |
4 | How To Get (And Stay) Fit At Any Age | Exercise is the closest thing we have to a mag... | https://www.womenshealthmag.com/uk/fitness/wor... | exercise closest thing magic bullet counter ef... | muscle mass, strength training, pelvic floor, ... |
print('Article Heading: ' + fitness_articles['Article Heading '][5])
print('Keywords extracted: ' + fitness_articles['keywords'][5])
Article Heading: Can Walking Help You Lose Weight? 9 Walking For Weight Loss Tips From The Experts Keywords extracted: weight loss, lose weight, walking weight, strikes ground, daily average
test = pd.read_csv('sweatreview_test.csv')
test
Article Heading | Article Copy | Article Link | cleaned_text | keywords | |
---|---|---|---|---|---|
0 | Sensor breakthrough brings us closer to blood ... | Blood glucose monitoring is touted to be the n... | https://www.digitaltrends.com/mobile/non-invas... | NaN | NaN |
1 | Why intense workouts like CrossFit and HIIT ar... | HIIT (high intensity interval training), boot ... | https://lifestyle.livemint.com/amp/health/fitn... | NaN | NaN |
2 | THE TRUTH ABOUT YOGA, FLEXIBILITY, & MOBILITY ... | To understand current methods and practice of ... | https://www.advancedhumanperformance.com/blog/... | NaN | NaN |
3 | GETTING STARTED WITH CROSSFIT | Um, so I got into CrossFit almost 10 years ago... | https://www.stephgaudreau.com/shawna-norton-cr... | NaN | NaN |
test['cleaned_text'] = test['Article Copy'].apply(lambda x: clean_string(x))
test['keywords'] = test['cleaned_text'].apply(lambda x: get_keywords(x))
test
Article Heading | Article Copy | Article Link | cleaned_text | keywords | |
---|---|---|---|---|---|
0 | Sensor breakthrough brings us closer to blood ... | Blood glucose monitoring is touted to be the n... | https://www.digitaltrends.com/mobile/non-invas... | blood glucose monitoring touted next big break... | blood glucose, glucose monitoring, apple watch... |
1 | Why intense workouts like CrossFit and HIIT ar... | HIIT (high intensity interval training), boot ... | https://lifestyle.livemint.com/amp/health/fitn... | hiit high intensity interval training boot cam... | interval training, rigorous exercise, hiit hig... |
2 | THE TRUTH ABOUT YOGA, FLEXIBILITY, & MOBILITY ... | To understand current methods and practice of ... | https://www.advancedhumanperformance.com/blog/... | understand current methods practice modern yog... | modern yoga, ancient practice, practice yoga, ... |
3 | GETTING STARTED WITH CROSSFIT | Um, so I got into CrossFit almost 10 years ago... | https://www.stephgaudreau.com/shawna-norton-cr... | um got crossfit almost 10 years ago 10 years o... | work people, fell love, nursing program, start... |
print('Article Heading: ' + test['Article Heading'][0])
print('Keywords extracted: ' + test['keywords'][0])
print()
print('Article Heading: ' + test['Article Heading'][1])
print('Keywords extracted: ' + test['keywords'][1])
print()
print('Article Heading: ' + test['Article Heading'][2])
print('Keywords extracted: ' + test['keywords'][2])
Article Heading: Sensor breakthrough brings us closer to blood glucose monitoring on wearables Keywords extracted: blood glucose, glucose monitoring, apple watch, glucose concentration, rockley photonics Article Heading: Why intense workouts like CrossFit and HIIT are good for you Keywords extracted: interval training, rigorous exercise, hiit high, warmup cool, period rigorous Article Heading: THE TRUTH ABOUT YOGA, FLEXIBILITY, & MOBILITY TRAINING Keywords extracted: modern yoga, ancient practice, practice yoga, ancient yoga, physical activity