How To Create A Word Cloud In Python | Tutorial [EASY] 💻
HTML-код
- Опубликовано: 8 фев 2025
- 👉 Explore All My Excel Solutions: pythonandvba.c...
𝗗𝗘𝗦𝗖𝗥𝗜𝗣𝗧𝗜𝗢𝗡
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
In this tutorial, I will show you, how to create a Word Cloud in Python by using the library called “wordcloud”.
👉 Link to wordcloud library documentation:
amueller.githu...
Get the code & excel file from GitHub:
github.com/Sve...
𝗧𝗢𝗢𝗟𝗦 𝗔𝗡𝗗 𝗥𝗘𝗦𝗢𝗨𝗥𝗖𝗘𝗦
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
🆓【𝗙𝗥𝗘𝗘】Excel Add-in (𝗠𝘆𝗧𝗼𝗼𝗹𝗕𝗲𝗹𝘁): pythonandvba.c...
📊 Dashboard Excel Add-In (𝗚𝗿𝗮𝗳𝗹𝘆): pythonandvba.c...
🎨 Cartoon Charts Excel Add-In (𝗖𝘂𝘁𝗲𝗣𝗹𝗼𝘁𝘀): pythonandvba.c...
🤪 Fun Emoji Excel Add-In (𝗘𝗺𝗼𝗷𝗶𝗳𝘆): pythonandvba.c...
📑 Excel Templates: pythonandvba.c...
🎓 My Courses: pythonandvba.c...
📚 Books, Tools, and More: pythonandvba.c...
𝗖𝗢𝗡𝗡𝗘𝗖𝗧 𝗪𝗜𝗧𝗛 𝗠𝗘
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
🔗 LinkedIn: / sven-bosau
📸 Instagram: / codingisfun_official
💻 GitHub: github.com/Sve...
💬 Discord: pythonandvba.c...
📬 Contact: pythonandvba.c...
☕ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲?
If you want to support this channel, you can buy me a coffee here: pythonandvba.c...
Very Easy Excellent way of getting the Word Cloud , thanks much from India , Bengaluru
Glad you liked it! Greetings to Bengaluru! :)
Thanks for this short tutorial! :)
Glad you liked it :)
Thanks, that was easy!
Glad you liked it. Thanks for watching.
Excelente tutorial! Muchísimas gracias!
Glad you liked it. Thanks for watching. Cheers, Sven ✌️
Thank you very much for your tutorials, they are very helpful, greetings from mexico
Thank you Oscar Hernández, I'm happy to hear that you've been finding the videos useful. Thanks for taking the time to leave a comment and for watching! Greeting to Mexico :)
Great tutorial ! Thanks very much !!!!
Thanks for watching! Glad it was helpful! :)
Quite useful!! Congrats!!
Thanks!
Thank you! =) Great tutorial.
Glad you liked it. Thanks for watching! :)
Thank you this was helpful
A pleasure! Thanks for watching the video :)
that's cool. many thanks!
Thanks! Glad you liked it :)
it didn't work for me in command prompt. what software do I first need for Windows?
Thanks for watching. You need to have Python installed on your machine. Cheers, Sven ✌️
I have the word cloud down, but I am attempting to do a list of names and wish for the first and last names to stay by each other even though there is a space, is that possible?
Thanks for watching. One possible solution I could think of is the following:
from pathlib import Path
import matplotlib.pyplot as plt
from wordcloud import STOPWORDS, WordCloud
TXT_FILE = Path.cwd() / "jeff_bezos_speech.txt"
# Read text
text = open(TXT_FILE, mode="r", encoding="utf-8").read()
# List of names (modify this with the names you are looking for)
names = ['Jeff Bezos', 'Elon Musk', 'Bill Gates']
# Replace spaces in names with underscores
for name in names:
text = text.replace(name, name.replace(' ', '_'))
stopwords = STOPWORDS
wc = WordCloud(background_color="white", stopwords=stopwords, height=600, width=400)
wc.generate(text)
# store to file
wc.to_file("wordcloud_output.png")
I hope it helps!
@@CodingIsFun thank you! is it possible for a wordcloud to use multiple fonts, like the words have a randomized chance on which font they use?
@@maxparsons9431 Your requirements are well noted. Yet, I receive many requests for creating individual solutions. As much as I want to help, I simply do not find the time in my daily schedule to develop & test all the different requests. I hope you can understand. Thank you!
which compiler are you using?
I am not quite sure if I understand your questions correctly, but the Library 'Wordcloud' depends on Matplotlib to generate & export the image.
@@CodingIsFun Oh, sorry for the wrong question. I am just using my command prompt and can not run the script. So I thought maybe it is because of the compiler or translator.
compiler says:
Traceback (most recent call last):
File "C:\Users\sarvar\Desktop\Wordcloud_Tutorial\wordcloud_example.py", line 2, in
from wordcloud import WordCloud, STOPWORDS
ModuleNotFoundError: No module named 'wordcloud'
@@sarvarbek8142 Could you kindly check if you have installed the required libraries (0:28 min)? It looks like, that you do not have 'wordcloud' installed.
If you still get an error, please let me know.
Cheers,
Sven
Hi Coding fun, when i am chaging my extention name of my txt file to py it is not convering as you. could you explain it in another video. Thanks
To convert a .txt file to a .py file, you need to:
Open the .txt file in a text editor such as Notepad or Sublime Text.
Write or copy Python code into the file.
Save the file with a .py file extension.
@@CodingIsFun Thanks for replying me i will try my best.
I was unable to install wordcloud in visual studio code please help me sir
What kind of error message did you get?
@@CodingIsFun " unable to find wheel "
@@bunnybaghi9989 Could you please try the following:
1) Download the .whl file compatible with your Python version and your windows distribution (32bit or 64bit) from here: www.lfd.uci.edu/~gohlke/pythonlibs/#wordcloud
2) cd to the file path
3) Run this command python -m pip install
OR, If you are using Anaconda, please enter the following in the Anaconda Prompt:
conda install -c conda.anaconda.org/conda-forge wordcloud
Hope it helps 🙏
Hi, noob question, why do you have to import the same packages two times?
Thanks!
Thanks for watching. Within the wordcloud module, I am importing the WordCloud class. You could also import all classes using "import wordcloud", then you could write:
wc = wordcloud.WordCloud(background_color="white", stopwords=stopwords, height=600, width=400)
I hope it helps!
All videos are very helpful..🙏 Thanks for your effort sir.. But how can i make wordcloud in different shapes??
Thanks for watching. Please check out the docs. Here is one example: amueller.github.io/word_cloud/auto_examples/frequency.html#sphx-glr-auto-examples-frequency-py
@@CodingIsFun Done... 👍 Thnks for ur reply
Hi, can you teach how to generate wordcloud but using Trigram?
Thanks for watching and your suggestion.
I'm having an error when installing wordcloud. It says, "this is an issue with the package mentioned above, not pip".
Thanks for watching. Hard to tell from a distance why you are facing an error. Sorry, that I cannot help.
@@CodingIsFun thanks anyways
Cheers! Thank you very much for the useful tutorial!!!
Could somebody advise me how to make it work with some text in cyrilic.
Many thanks in advance.
Thank you very much.
I tried it out. For me, it is also working with Cyrillic (see sample code below).
Alternatively, you could also install a font on your machine (which supports Cyrillic) and specify the path under "font_path".
Let me know if that does not work for you.
Cheers,
Sven
CODE BELOW 👇
---------------------------------------------------------------------------------------
import matplotlib.pyplot as plt
from wordcloud import WordCloud, STOPWORDS
# Read text
text = """Статья 1 Все люди рождаются свободными и равными в своем достоинстве и правах.
Они наделены разумом и совестью и должны поступать в отношении друг друга в духе братства."""
stopwords = STOPWORDS
wc = WordCloud(
background_color='white',
stopwords=stopwords,
# font_path='/Library/Fonts/NotoSansCJKjp-Light.otf',
height = 600,
width=400
)
wc.generate(text)
# store to file
wc.to_file('wordcloud_output.png')
awsome tutorial! but how do can you display 2 words together like " Red apple" or "Happy Smile"
Thank you for watching the video and for your question. Unfortunately, I do not know how to implement that right off the bat. I would also need to search the internet for a solution. Sorry that I cannot help!
@@CodingIsFun thanks alot for the answer. I will try to solve it, it is an good lesson to fix stuff by my own but it is hard tho xD
Hi, nice tutorial. :D
Is it possible to add an transparent background?
Thanks!
Here you are:
wc = WordCloud(mode = "RGBA", background_color=None, height=600, width=400)
Hey bro,
How can I get word clouds in text format
Thanks for watching. Off the top of my head, I'm not sure how to do that. You might need to do a little Google research. Good luck! Cheers, Sven ✌️
i can't install wordcloud in my python, why??
Do you receive any error message?
How to add hyperlink on words of cloud?
Thanks for watching the video and for your question! I'm sorry to say that I don't have the answer right off the top of my head. I'll need to do a little digging online to see if I can find a solution. Sorry I couldn't be more help!
Only heart!!! No hint😭
I have many documents and a list of words that are statistically significant across all the documents combined.
I want to make a word cloud for each document class, feeding in a list of words and the average expression of those words within each set of documents.
What function should I use?
Thank you for watching the video. Your questions are great, but finding the time to answer them is difficult. Kindly understand that I receive many requests for individual solutions or modifications. That said, you might want to join our Discord server ( pythonandvba.com/discord ) and post your question there. Thanks for your understanding. Happy Coding!
easy
Nice :)
Hi brother, how could I avoid spanish useless words. regards from Chile!
*Hello Edgardo AS, thanks for watching the video and your question.*
You could provide a list of words [stopwords], which you would like to exclude. Kindly see the example below:
stopwords = ['hola', 'soy', 'Sven']
wc = WordCloud(
background_color='white',
stopwords=stopwords,
height = 600,
width=400
)
Hope it helps 🙏
Cheers,
Sven
Thanks a lot, it worked.