This is the second guided project of Dataquest.io
#open and read csv file
from csv import reader
opened_file = open("hacker_news.csv")
readed_file = reader(opened_file)
hn = list(opened_file)
print(hn[:5])
['id,title,url,num_points,num_comments,author,created_at\n', '12224879,Interactive Dynamic Video,http://www.interactivedynamicvideo.com/,386,52,ne0phyte,8/4/2016 11:52\n', '10975351,How to Use Open Source and Shut the Fuck Up at the Same Time,http://hueniverse.com/2016/01/26/how-to-use-open-source-and-shut-the-fuck-up-at-the-same-time/,39,10,josep2,1/26/2016 19:30\n', "11964716,Florida DJs May Face Felony for April Fools' Water Joke,http://www.thewire.com/entertainment/2013/04/florida-djs-april-fools-water-joke/63798/,2,1,vezycash,6/23/2016 22:20\n", '11919867,Technology ventures: From Idea to Enterprise,https://www.amazon.com/Technology-Ventures-Enterprise-Thomas-Byers/dp/0073523429,3,1,hswarna,6/17/2016 0:01\n']
#remove the header and make it separate
#from the data we're going to analyse
headers = hn[0]
hn = hn[1:]
print(headers)
print(hn[:5])
id,title,url,num_points,num_comments,author,created_at ['12224879,Interactive Dynamic Video,http://www.interactivedynamicvideo.com/,386,52,ne0phyte,8/4/2016 11:52\n', '10975351,How to Use Open Source and Shut the Fuck Up at the Same Time,http://hueniverse.com/2016/01/26/how-to-use-open-source-and-shut-the-fuck-up-at-the-same-time/,39,10,josep2,1/26/2016 19:30\n', "11964716,Florida DJs May Face Felony for April Fools' Water Joke,http://www.thewire.com/entertainment/2013/04/florida-djs-april-fools-water-joke/63798/,2,1,vezycash,6/23/2016 22:20\n", '11919867,Technology ventures: From Idea to Enterprise,https://www.amazon.com/Technology-Ventures-Enterprise-Thomas-Byers/dp/0073523429,3,1,hswarna,6/17/2016 0:01\n', '10301696,Note by Note: The Making of Steinway L1037 (2007),http://www.nytimes.com/2007/11/07/movies/07stein.html?_r=0,8,2,walterbell,9/30/2015 4:12\n']
#extracting 'Ask HN' and 'Show HN' posts
ask_hn_posts = []
show_hn_posts = []
other_hn_posts = []
for post in hn:
title = post[1]
if title.lower().startswith("ask hn"):
ask_hn_posts.append(post)
elif title.lower().startswith("show hn"):
show_hn_posts.append(post)
else:
other_hn_posts.append(post)
print(len(ask_hn_posts))
print(len(show_hn_posts))
print(len(other_hn_posts))
print("\n")
print(ask_hn_posts[:5])
print(show_hn_posts[:5])
print(other_hn_posts[:5])
0 0 20100 [] [] ['12224879,Interactive Dynamic Video,http://www.interactivedynamicvideo.com/,386,52,ne0phyte,8/4/2016 11:52\n', '10975351,How to Use Open Source and Shut the Fuck Up at the Same Time,http://hueniverse.com/2016/01/26/how-to-use-open-source-and-shut-the-fuck-up-at-the-same-time/,39,10,josep2,1/26/2016 19:30\n', "11964716,Florida DJs May Face Felony for April Fools' Water Joke,http://www.thewire.com/entertainment/2013/04/florida-djs-april-fools-water-joke/63798/,2,1,vezycash,6/23/2016 22:20\n", '11919867,Technology ventures: From Idea to Enterprise,https://www.amazon.com/Technology-Ventures-Enterprise-Thomas-Byers/dp/0073523429,3,1,hswarna,6/17/2016 0:01\n', '10301696,Note by Note: The Making of Steinway L1037 (2007),http://www.nytimes.com/2007/11/07/movies/07stein.html?_r=0,8,2,walterbell,9/30/2015 4:12\n']