Generate a word cloud to show frequenices of numbers in Python2019 Community Moderator ElectionWord cloud generator for RailsAdding new column to existing DataFrame in Python pandasHow to create a word cloud from a corpus in Python?Installation Issue with matplotlib PythonAutotune word cloud parameters in pythonWord Cloud Generatorword cloud generation in RHow to ignore some words in a word cloud in Python?Less Frequent Words appearing bigger - WordCloud in Pythonword cloud does not show the frequency of the words correctly
I seem to dance, I am not a dancer. Who am I?
How to get the n-th line after a grepped one?
What (if any) is the reason to buy in small local stores?
What is the significance behind "40 days" that often appears in the Bible?
How to generate binary array whose elements with values 1 are randomly drawn
What does "^L" mean in C?
Bash - pair each line of file
Do native speakers use "ultima" and "proxima" frequently in spoken English?
Using Past-Perfect interchangeably with the Past Continuous
World War I as a war of liberals against authoritarians?
What are substitutions for coconut in curry?
Turning a hard to access nut?
What does "Four-F." mean?
In the 1924 version of The Thief of Bagdad, no character is named, right?
Does the attack bonus from a Masterwork weapon stack with the attack bonus from Masterwork ammunition?
Violin - Can double stops be played when the strings are not next to each other?
Print a physical multiplication table
The average age of first marriage in Russia
Matrix using tikz package
Why is there so much iron?
What is the term when voters “dishonestly” choose something that they do not want to choose?
Geography in 3D perspective
Existence of a celestial body big enough for early civilization to be thought of as a second moon
How could an airship be repaired midflight?
Generate a word cloud to show frequenices of numbers in Python
2019 Community Moderator ElectionWord cloud generator for RailsAdding new column to existing DataFrame in Python pandasHow to create a word cloud from a corpus in Python?Installation Issue with matplotlib PythonAutotune word cloud parameters in pythonWord Cloud Generatorword cloud generation in RHow to ignore some words in a word cloud in Python?Less Frequent Words appearing bigger - WordCloud in Pythonword cloud does not show the frequency of the words correctly
I have a pandas dataframe which consists of grade points of students. I want to generate the word cloud or number cloud for the grades. Is there any way to achieve it. I tried all possible ways but all my efforts in vain.
Basically what I want is word cloud that contains numbers in it. from the column CGPA.
Here is what I tried :
import pandas as pd
from wordcloud import WordCloud
import matplotlib.pyplot as plt
df = pd.read_csv("VTU_marks.csv")
# rounding off
df = df[df['CGPA'].isnull() == False]
df['CGPA'] = df['CGPA'].round(decimals=2)
wordcloud = WordCloud(max_font_size=50,max_words=100,background_color="white").generate(string)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()
But I am getting an error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-47-29ec36ebbb1e> in <module>()
----> 1 wordcloud = WordCloud(max_font_size=50, max_words=100, background_color="white").generate(string)
2 plt.figure()
3 plt.imshow(wordcloud, interpolation="bilinear")
4 plt.axis("off")
5 plt.show()
/usr/local/lib/python3.6/dist-packages/wordcloud/wordcloud.py in generate(self, text)
603 self
604 """
--> 605 return self.generate_from_text(text)
606
607 def _check_generated(self):
/usr/local/lib/python3.6/dist-packages/wordcloud/wordcloud.py in generate_from_text(self, text)
585 """
586 words = self.process_text(text)
--> 587 self.generate_from_frequencies(words)
588 return self
589
/usr/local/lib/python3.6/dist-packages/wordcloud/wordcloud.py in generate_from_frequencies(self, frequencies, max_font_size)
381 if len(frequencies) <= 0:
382 raise ValueError("We need at least 1 word to plot a word cloud, "
--> 383 "got %d." % len(frequencies))
384 frequencies = frequencies[:self.max_words]
385
ValueError: We need at least 1 word to plot a word cloud, got 0.
You can find the data here.
Any help to generate the plot will be highly appreciated.
pandas matplotlib nlp nltk word-cloud
add a comment |
I have a pandas dataframe which consists of grade points of students. I want to generate the word cloud or number cloud for the grades. Is there any way to achieve it. I tried all possible ways but all my efforts in vain.
Basically what I want is word cloud that contains numbers in it. from the column CGPA.
Here is what I tried :
import pandas as pd
from wordcloud import WordCloud
import matplotlib.pyplot as plt
df = pd.read_csv("VTU_marks.csv")
# rounding off
df = df[df['CGPA'].isnull() == False]
df['CGPA'] = df['CGPA'].round(decimals=2)
wordcloud = WordCloud(max_font_size=50,max_words=100,background_color="white").generate(string)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()
But I am getting an error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-47-29ec36ebbb1e> in <module>()
----> 1 wordcloud = WordCloud(max_font_size=50, max_words=100, background_color="white").generate(string)
2 plt.figure()
3 plt.imshow(wordcloud, interpolation="bilinear")
4 plt.axis("off")
5 plt.show()
/usr/local/lib/python3.6/dist-packages/wordcloud/wordcloud.py in generate(self, text)
603 self
604 """
--> 605 return self.generate_from_text(text)
606
607 def _check_generated(self):
/usr/local/lib/python3.6/dist-packages/wordcloud/wordcloud.py in generate_from_text(self, text)
585 """
586 words = self.process_text(text)
--> 587 self.generate_from_frequencies(words)
588 return self
589
/usr/local/lib/python3.6/dist-packages/wordcloud/wordcloud.py in generate_from_frequencies(self, frequencies, max_font_size)
381 if len(frequencies) <= 0:
382 raise ValueError("We need at least 1 word to plot a word cloud, "
--> 383 "got %d." % len(frequencies))
384 frequencies = frequencies[:self.max_words]
385
ValueError: We need at least 1 word to plot a word cloud, got 0.
You can find the data here.
Any help to generate the plot will be highly appreciated.
pandas matplotlib nlp nltk word-cloud
add a comment |
I have a pandas dataframe which consists of grade points of students. I want to generate the word cloud or number cloud for the grades. Is there any way to achieve it. I tried all possible ways but all my efforts in vain.
Basically what I want is word cloud that contains numbers in it. from the column CGPA.
Here is what I tried :
import pandas as pd
from wordcloud import WordCloud
import matplotlib.pyplot as plt
df = pd.read_csv("VTU_marks.csv")
# rounding off
df = df[df['CGPA'].isnull() == False]
df['CGPA'] = df['CGPA'].round(decimals=2)
wordcloud = WordCloud(max_font_size=50,max_words=100,background_color="white").generate(string)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()
But I am getting an error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-47-29ec36ebbb1e> in <module>()
----> 1 wordcloud = WordCloud(max_font_size=50, max_words=100, background_color="white").generate(string)
2 plt.figure()
3 plt.imshow(wordcloud, interpolation="bilinear")
4 plt.axis("off")
5 plt.show()
/usr/local/lib/python3.6/dist-packages/wordcloud/wordcloud.py in generate(self, text)
603 self
604 """
--> 605 return self.generate_from_text(text)
606
607 def _check_generated(self):
/usr/local/lib/python3.6/dist-packages/wordcloud/wordcloud.py in generate_from_text(self, text)
585 """
586 words = self.process_text(text)
--> 587 self.generate_from_frequencies(words)
588 return self
589
/usr/local/lib/python3.6/dist-packages/wordcloud/wordcloud.py in generate_from_frequencies(self, frequencies, max_font_size)
381 if len(frequencies) <= 0:
382 raise ValueError("We need at least 1 word to plot a word cloud, "
--> 383 "got %d." % len(frequencies))
384 frequencies = frequencies[:self.max_words]
385
ValueError: We need at least 1 word to plot a word cloud, got 0.
You can find the data here.
Any help to generate the plot will be highly appreciated.
pandas matplotlib nlp nltk word-cloud
I have a pandas dataframe which consists of grade points of students. I want to generate the word cloud or number cloud for the grades. Is there any way to achieve it. I tried all possible ways but all my efforts in vain.
Basically what I want is word cloud that contains numbers in it. from the column CGPA.
Here is what I tried :
import pandas as pd
from wordcloud import WordCloud
import matplotlib.pyplot as plt
df = pd.read_csv("VTU_marks.csv")
# rounding off
df = df[df['CGPA'].isnull() == False]
df['CGPA'] = df['CGPA'].round(decimals=2)
wordcloud = WordCloud(max_font_size=50,max_words=100,background_color="white").generate(string)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()
But I am getting an error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-47-29ec36ebbb1e> in <module>()
----> 1 wordcloud = WordCloud(max_font_size=50, max_words=100, background_color="white").generate(string)
2 plt.figure()
3 plt.imshow(wordcloud, interpolation="bilinear")
4 plt.axis("off")
5 plt.show()
/usr/local/lib/python3.6/dist-packages/wordcloud/wordcloud.py in generate(self, text)
603 self
604 """
--> 605 return self.generate_from_text(text)
606
607 def _check_generated(self):
/usr/local/lib/python3.6/dist-packages/wordcloud/wordcloud.py in generate_from_text(self, text)
585 """
586 words = self.process_text(text)
--> 587 self.generate_from_frequencies(words)
588 return self
589
/usr/local/lib/python3.6/dist-packages/wordcloud/wordcloud.py in generate_from_frequencies(self, frequencies, max_font_size)
381 if len(frequencies) <= 0:
382 raise ValueError("We need at least 1 word to plot a word cloud, "
--> 383 "got %d." % len(frequencies))
384 frequencies = frequencies[:self.max_words]
385
ValueError: We need at least 1 word to plot a word cloud, got 0.
You can find the data here.
Any help to generate the plot will be highly appreciated.
pandas matplotlib nlp nltk word-cloud
pandas matplotlib nlp nltk word-cloud
edited Mar 7 at 21:14
Jack
1,8951117
1,8951117
asked Mar 7 at 14:36
Himanshu PoddarHimanshu Poddar
4881720
4881720
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
After setting up your data and rounding as desired we can count up the frequency of each score:
counts = df['CGPA'].value_counts()
We need to make sure that the indices here are strings, floats will raise an error (this is what was wrong in your example attempt). So, we can convert them to strings as:
counts.index = counts.index.map(str)
#Below alternative works for pandas versions >= 0.19.0
#counts.index = counts.index.astype(str)
We can then use the .generate_from_frequencies
method to get what you desire:
wordcloud = WordCloud().generate_from_frequencies(counts)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()
This gave me the following:
Full MWE:
import pandas as pd
from wordcloud import WordCloud
import matplotlib.pyplot as plt
df = pd.read_csv("VTU_marks.csv")
# rounding off
df = df[df['CGPA'].isnull() == False]
df['CGPA'] = df['CGPA'].round(decimals=2)
counts = df['CGPA'].value_counts()
counts.index = counts.index.map(str)
#counts.index = counts.index.astype(str)
wordcloud = WordCloud().generate_from_frequencies(counts)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()
hi there thanks a lot for the help but as you are saying that the values are unique. Ok but is there any way to show those values in the word cloud
– Himanshu Poddar
Mar 7 at 17:12
Actually, looking again I was wrong about the uniqueness. I'll update my answer
– Jack
Mar 7 at 17:14
Jack you are my saviour Thank you so much .
– Himanshu Poddar
Mar 7 at 17:17
You're welcome. Glad I could help :)
– Jack
Mar 7 at 17:17
Tried to follow the same thing but getting an error TypeError: argument of type 'float' is not iterable can you please help me out
– Himanshu Poddar
Mar 7 at 17:25
|
show 2 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55046327%2fgenerate-a-word-cloud-to-show-frequenices-of-numbers-in-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
After setting up your data and rounding as desired we can count up the frequency of each score:
counts = df['CGPA'].value_counts()
We need to make sure that the indices here are strings, floats will raise an error (this is what was wrong in your example attempt). So, we can convert them to strings as:
counts.index = counts.index.map(str)
#Below alternative works for pandas versions >= 0.19.0
#counts.index = counts.index.astype(str)
We can then use the .generate_from_frequencies
method to get what you desire:
wordcloud = WordCloud().generate_from_frequencies(counts)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()
This gave me the following:
Full MWE:
import pandas as pd
from wordcloud import WordCloud
import matplotlib.pyplot as plt
df = pd.read_csv("VTU_marks.csv")
# rounding off
df = df[df['CGPA'].isnull() == False]
df['CGPA'] = df['CGPA'].round(decimals=2)
counts = df['CGPA'].value_counts()
counts.index = counts.index.map(str)
#counts.index = counts.index.astype(str)
wordcloud = WordCloud().generate_from_frequencies(counts)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()
hi there thanks a lot for the help but as you are saying that the values are unique. Ok but is there any way to show those values in the word cloud
– Himanshu Poddar
Mar 7 at 17:12
Actually, looking again I was wrong about the uniqueness. I'll update my answer
– Jack
Mar 7 at 17:14
Jack you are my saviour Thank you so much .
– Himanshu Poddar
Mar 7 at 17:17
You're welcome. Glad I could help :)
– Jack
Mar 7 at 17:17
Tried to follow the same thing but getting an error TypeError: argument of type 'float' is not iterable can you please help me out
– Himanshu Poddar
Mar 7 at 17:25
|
show 2 more comments
After setting up your data and rounding as desired we can count up the frequency of each score:
counts = df['CGPA'].value_counts()
We need to make sure that the indices here are strings, floats will raise an error (this is what was wrong in your example attempt). So, we can convert them to strings as:
counts.index = counts.index.map(str)
#Below alternative works for pandas versions >= 0.19.0
#counts.index = counts.index.astype(str)
We can then use the .generate_from_frequencies
method to get what you desire:
wordcloud = WordCloud().generate_from_frequencies(counts)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()
This gave me the following:
Full MWE:
import pandas as pd
from wordcloud import WordCloud
import matplotlib.pyplot as plt
df = pd.read_csv("VTU_marks.csv")
# rounding off
df = df[df['CGPA'].isnull() == False]
df['CGPA'] = df['CGPA'].round(decimals=2)
counts = df['CGPA'].value_counts()
counts.index = counts.index.map(str)
#counts.index = counts.index.astype(str)
wordcloud = WordCloud().generate_from_frequencies(counts)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()
hi there thanks a lot for the help but as you are saying that the values are unique. Ok but is there any way to show those values in the word cloud
– Himanshu Poddar
Mar 7 at 17:12
Actually, looking again I was wrong about the uniqueness. I'll update my answer
– Jack
Mar 7 at 17:14
Jack you are my saviour Thank you so much .
– Himanshu Poddar
Mar 7 at 17:17
You're welcome. Glad I could help :)
– Jack
Mar 7 at 17:17
Tried to follow the same thing but getting an error TypeError: argument of type 'float' is not iterable can you please help me out
– Himanshu Poddar
Mar 7 at 17:25
|
show 2 more comments
After setting up your data and rounding as desired we can count up the frequency of each score:
counts = df['CGPA'].value_counts()
We need to make sure that the indices here are strings, floats will raise an error (this is what was wrong in your example attempt). So, we can convert them to strings as:
counts.index = counts.index.map(str)
#Below alternative works for pandas versions >= 0.19.0
#counts.index = counts.index.astype(str)
We can then use the .generate_from_frequencies
method to get what you desire:
wordcloud = WordCloud().generate_from_frequencies(counts)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()
This gave me the following:
Full MWE:
import pandas as pd
from wordcloud import WordCloud
import matplotlib.pyplot as plt
df = pd.read_csv("VTU_marks.csv")
# rounding off
df = df[df['CGPA'].isnull() == False]
df['CGPA'] = df['CGPA'].round(decimals=2)
counts = df['CGPA'].value_counts()
counts.index = counts.index.map(str)
#counts.index = counts.index.astype(str)
wordcloud = WordCloud().generate_from_frequencies(counts)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()
After setting up your data and rounding as desired we can count up the frequency of each score:
counts = df['CGPA'].value_counts()
We need to make sure that the indices here are strings, floats will raise an error (this is what was wrong in your example attempt). So, we can convert them to strings as:
counts.index = counts.index.map(str)
#Below alternative works for pandas versions >= 0.19.0
#counts.index = counts.index.astype(str)
We can then use the .generate_from_frequencies
method to get what you desire:
wordcloud = WordCloud().generate_from_frequencies(counts)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()
This gave me the following:
Full MWE:
import pandas as pd
from wordcloud import WordCloud
import matplotlib.pyplot as plt
df = pd.read_csv("VTU_marks.csv")
# rounding off
df = df[df['CGPA'].isnull() == False]
df['CGPA'] = df['CGPA'].round(decimals=2)
counts = df['CGPA'].value_counts()
counts.index = counts.index.map(str)
#counts.index = counts.index.astype(str)
wordcloud = WordCloud().generate_from_frequencies(counts)
plt.figure()
plt.imshow(wordcloud, interpolation="bilinear")
plt.axis("off")
plt.show()
edited Mar 8 at 9:24
answered Mar 7 at 16:59
JackJack
1,8951117
1,8951117
hi there thanks a lot for the help but as you are saying that the values are unique. Ok but is there any way to show those values in the word cloud
– Himanshu Poddar
Mar 7 at 17:12
Actually, looking again I was wrong about the uniqueness. I'll update my answer
– Jack
Mar 7 at 17:14
Jack you are my saviour Thank you so much .
– Himanshu Poddar
Mar 7 at 17:17
You're welcome. Glad I could help :)
– Jack
Mar 7 at 17:17
Tried to follow the same thing but getting an error TypeError: argument of type 'float' is not iterable can you please help me out
– Himanshu Poddar
Mar 7 at 17:25
|
show 2 more comments
hi there thanks a lot for the help but as you are saying that the values are unique. Ok but is there any way to show those values in the word cloud
– Himanshu Poddar
Mar 7 at 17:12
Actually, looking again I was wrong about the uniqueness. I'll update my answer
– Jack
Mar 7 at 17:14
Jack you are my saviour Thank you so much .
– Himanshu Poddar
Mar 7 at 17:17
You're welcome. Glad I could help :)
– Jack
Mar 7 at 17:17
Tried to follow the same thing but getting an error TypeError: argument of type 'float' is not iterable can you please help me out
– Himanshu Poddar
Mar 7 at 17:25
hi there thanks a lot for the help but as you are saying that the values are unique. Ok but is there any way to show those values in the word cloud
– Himanshu Poddar
Mar 7 at 17:12
hi there thanks a lot for the help but as you are saying that the values are unique. Ok but is there any way to show those values in the word cloud
– Himanshu Poddar
Mar 7 at 17:12
Actually, looking again I was wrong about the uniqueness. I'll update my answer
– Jack
Mar 7 at 17:14
Actually, looking again I was wrong about the uniqueness. I'll update my answer
– Jack
Mar 7 at 17:14
Jack you are my saviour Thank you so much .
– Himanshu Poddar
Mar 7 at 17:17
Jack you are my saviour Thank you so much .
– Himanshu Poddar
Mar 7 at 17:17
You're welcome. Glad I could help :)
– Jack
Mar 7 at 17:17
You're welcome. Glad I could help :)
– Jack
Mar 7 at 17:17
Tried to follow the same thing but getting an error TypeError: argument of type 'float' is not iterable can you please help me out
– Himanshu Poddar
Mar 7 at 17:25
Tried to follow the same thing but getting an error TypeError: argument of type 'float' is not iterable can you please help me out
– Himanshu Poddar
Mar 7 at 17:25
|
show 2 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55046327%2fgenerate-a-word-cloud-to-show-frequenices-of-numbers-in-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown