Jul-29-2021, 01:07 PM
best_5 = sorted_swap[:4] for row in best_5: hour = row[1] hour = dt.datetime.strptime(hour, '%H') hour = hour.strftime('%H') average = row[0] print(type(average)) string = "{a} {c:.2f} average comments per post" for_final = string.format(a=average, c=hour) print(for_final)This is the full list
Output:[[38.5948275862069, '15'], [23.810344827586206, '02'], [21.525, '20'], [16.796296296296298, '16'], [16.009174311926607, '21'], [14.741176470588234, '13'], [13.440677966101696, '10'], [13.24074074074074, '18'], [13.233644859813085, '14'], [11.46, '17'], [11.383333333333333, '01'], [11.051724137931034, '11'], [10.8, '19'], [10.25, '08'], [10.08695652173913, '05'], [9.41095890410959, '12'], [9.022727272727273, '06'], [8.12962962962963, '00'], [7.985294117647059, '23'], [7.852941176470588, '07'], [7.796296296296297, '03'], [7.170212765957447, '04'], [6.746478873239437, '22'], [5.5777777777777775, '09']]
Hi so in general i want to understand what is the issue in those lines of codes---------------------------------------------------------------------------
Error:ValueError Traceback (most recent call last)
<ipython-input-8-9994e6baa044> in <module>
10 print(type(average))
11 string = "{a} {c:.2f} average comments per post"
---> 12 for_final = string.format(a=average, c=hour)
13 print(for_final)
ValueError: Unknown format code 'f' for object of type 'str'
Thanks