i have csv file data in following format
column1 column2 hello 1 film 9 chicken 20 etc etc
how can generate word cloud using such file python? tried using wordcloud package andreas mueller doesn't accept csv. tried using generate_from_frequencies option such
reader = csv.reader(open('wordcount.csv', 'r',newline='\n')) d = {} k,v in reader: d[k] = v # generate word cloud image wordcloud = wordcloud().generate_from_frequencies(d)
but kept getting error below.
file "wordcloudtest.py", line 22, in <module> wordcloud = wordcloud().generate_from_frequencies(d) file "c:\users\lenovo\anaconda3\lib\site-packages\wordcloud\wordcloud.py", line 360, in generate_from_frequenci word, freq in frequencies] file "c:\users\lenovo\anaconda3\lib\site-packages\wordcloud\wordcloud.py", line 360, in <listcomp> word, freq in frequencies] typeerror: unsupported operand type(s) /: 'str' , 'float'
convert value float.
d[k] = float(v)
csvreader gives strings, whereas generate_from_frequencies
requires dict str
float
.
Comments
Post a Comment