Python Forum
Python issue - Data science - Help is needed
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python issue - Data science - Help is needed
#1
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
buran write Jul-29-2021, 02:37 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply


Messages In This Thread
Python issue - Data science - Help is needed - by yovel - Jul-29-2021, 01:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Issue in writing sql data into csv for decimal value to scientific notation mg24 8 2,992 Dec-06-2022, 11:09 AM
Last Post: mg24
  Issue in changing data format (2 bytes) into a 16 bit data. GiggsB 11 2,638 Jul-25-2022, 03:19 PM
Last Post: deanhystad
  Data Science sadra_ss 1 36,409 Oct-14-2021, 07:01 PM
Last Post: buran
  blank graph with matplotlib from a csv file / data type issue arsentievalex 0 1,943 Apr-06-2021, 10:08 AM
Last Post: arsentievalex
  Databricks, Python Notebook Data file use issue khalid2200 0 1,749 Nov-25-2020, 03:36 AM
Last Post: khalid2200
  Help needed for a python package keysson 1 2,198 Sep-02-2020, 03:37 AM
Last Post: Larz60+
  Issue accessing data from Dictionary/List in the right format LuisSatch 2 2,196 Jul-25-2020, 06:12 AM
Last Post: LuisSatch
  Absolutely new to python - basic advise needed mariolucas75 2 2,046 Jun-12-2020, 08:36 PM
Last Post: Yoriz
  Issue with creating an array of pixel data for PNG files in Google Colab The_Sarco 1 1,920 Apr-29-2020, 12:03 AM
Last Post: bowlofred
Smile Help needed. Python Newbie!, it will be fun. knightdea 3 2,610 Oct-13-2019, 08:50 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020