Reputation: 477
I have a table with records which have a Munsell color assigned which I could potentially turn in RGB. Is there a way for Python to read the RGB value and color a word accordingly? I've been researching on it, and it seems that it is maybe a css/js task, not a Python task but as I was doing the analysis in Python, I was wondering if I could create a word cloud with words colored in a corresponding color assigned.
Intput:
Output:
Upvotes: 1
Views: 347
Reputation: 592
You cannot have colors in CSV file. but if you want, you can output in the console like this:
I am not sure about RGB, but you can use Colorama for colors.
Something like:
from colorama import init, Fore
import pandas
init()
csv = pandas.read_csv(file_path)
for row, munsell, color in zip(csv['row'], csv['munsell'], csv['rgb']):
print(getattr(Fore, color) + f"row: {row}, munsell: {munsell}" + Fore.RESET)
Fore.RESET is important. always add it at the end.
in your csv file, your RGB color codes need to match colorama's attributes.
example of a csv file:
row,munsell,rgb
1,10RP,RED
2,20RP, LIGHTRED_EX
EDIT:
You need to install colorama
And install pandas
EDIT2:
Changed the for loop a bit to match your case.
Upvotes: 1