Issue
I need to get this output as rows. How to do that. Below is the code I used to make prints.
print("Horizontal Histogram")
print("Progress", progress_number, " : ", star_progress)
print("Trailer", trailer_number, " : ", star_trailer)
print("Retriever", retriever_number, " : ", star_retriever)
print("Excluded", excluded_number, " : ", star_excluded)
So this is the output I get :
Horizontal Histogram
Progress 1 : *
Trailer 0 :
Retriever 0 :
Excluded 0 :
This is the output I need :
Progress Trailing Retriever Excluded
* * * *
*
I use append to make lists with "*" items inside the dictionary.
for x in range(progress_number):
progress_list.append("*")
This is how dictionary looks like:
df = pd.DataFrame({'Progress': [progress_list], 'Trailer':
[trailer_list], 'Retriever': [retriever_list], 'Exclude':
[exclude_list]})
print(tabulate(df, headers='keys', tablefmt='plain', showindex=False))
I tried with pandas and tabulate modules. But I cant print my lists vertically in the dictionary.
Progress Trailer Retriever Exclude
['*', '*', '*']
Solution
It's not particularly straightforward. You have to do this one row at a time, checking each value to see if it still needs to be printed.
data = {}
data['Progress'] = 3
data['Trailer'] = 1
data['Retriever'] = 4
data['Excluded'] = 1
titles = list(data.keys())
maximum = max(data.values())
fmt = "{:12}"*len(titles)
print(fmt.format(*titles))
for row in range(maximum):
histo = [' *' if v > row else '' for v in data.values()]
print(fmt.format(*histo))
Output:
Progress Trailer Retriever Excluded
* * * *
* *
* *
*
Answered By - Tim Roberts
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.