'ValueError in python while reading .txt file for Wordcloud project
with open('checking.txt', 'r') as file:
data = file.read().replace('\n', '')
print(data)
word_cloud = WordCloud(collocations = False, background_color = 'black').generate(data)`
This is the error that I got:
ValueError: We need at least 1 word to plot a word cloud, got 0.
Edit: The problem was that I had not provided the absolute path for reading the text file.
Solution 1:[1]
Does this worked ?
with open('abcd.txt', 'r') as file:
data = file.read().replace('\n', '')
print(data)
word_cloud = WordCloud(collocations = False, background_color = 'black').generate(data)
Solution 2:[2]
Could you please provide the contents of checking.txt or at least what does print(data) prints. I tried on my dummy data and it works. If I print(data) it should print the words separated by space and the datatype of the data variable is <class 'str'>. Check if it is in that format or not.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Adarsh Wase |
| Solution 2 | Shreyas Vedpathak |

