I have an output in the Console. Unfortunately the texts are of different length and therefore looks very shifted. Is there an option that writes the texts below each other, no matter how many characters are in front of them, so that the output looks the way I want it to look?
I would not like to use another library for this.
print(65 * '_')
print('algorithm\t\t\tsil\t\tdbs')
results = ['Agglomerative Clustering', 0.8665, 0.4200]
formatter_result = ("{:9s}\t\t{:.4f}\t{:.4f}")
print(formatter_result.format(*results))
results = ['k-Means', 0.9865, 0.1200]
formatter_result = ("{:9s}\t\t{:.4f}\t{:.4f}")
print(formatter_result.format(*results))
print(65 * '_')
What I have
_________________________________________________________________
algorithm sil dbs
Agglomerative Clustering 0.8665 0.4200
k-Means 0.9865 0.1200
_________________________________________________________________
What I want
_________________________________________________________________
algorithm sil dbs
Agglomerative Clustering 0.8665 0.4200
k-Means 0.9865 0.1200
_________________________________________________________________
I looked at Printing Lists as Tabular Data and tried it, but dosen't work for me
print(65 * '_')
heading = ['algorithm', 'sil', 'dbs']
result1 = ['Agglomerative Clustering', 0.8665, 0.4200]
result2 = ['k-Means', 0.9865, 0.1200]
ab = np.array([heading, result1, result2])
for row in ab:
print("{: >20} {: >20} {: >20}".format(*row))
print(65 * '_')
_________________________________________________________________
algorithm sil dbs
Agglomerative Clustering 0.8665 0.42
k-Means 0.9865 0.12
_________________________________________________________________