Guided Project 2: Hackers News Project

Screen Link: https://app.dataquest.io/m/356/guided-project%3A-exploring-hacker-news-posts/4/calculating-the-average-number-of-comments-for-ask-hn-and-show-hn-posts

Your Code:

# Average ask comments:
total_ask_comments = 0
for row in ask_posts:
    total_ask_comments = total_ask_comments + int(row[4]) 
    
avg_ask_comments = total_ask_comments/len(ask_posts)
print('Average ask comments:',avg_ask_comment)
    

# Average show comments:
total_show_comments = 0
for row in show_posts:
    total_show_comments += int(row[4])
    
avg_show_comments = total_show_comments/len(show_posts)
print('Average show comments:',avg_show_comment)

What I expected to happen: I expected the string of number of comments in column 5 to be converted to an integer

What actually happened:

<ipython-input-32-bb49682bba3b> in <module>()
      2 total_ask_comments = 0
      3 for row in ask_posts:
----> 4     total_ask_comments = total_ask_comments + int(row[4])
      5 
      6 avg_ask_comments = total_ask_comments/len(ask_posts)

ValueError: invalid literal for int() with base 10: 'h'``` to format properly

Other details: if i am on the right path of leanring, then i think there is a value 'h' in the particular column of the dataset. So how do i solve it?

Hi @priyankagujjari94,
You can take look to this post
https://community.dataquest.io/t/guided-project-exploring-hackers-news-post/270280/2?u=bahmed21

1 Like

Thank you very much. Problem solved and i am glad that i was thinking of something along the same lines of appending the whole row instead of just the title column.

1 Like