AS03: Summarizing Data by Pandas#
Q1. Loading data (50 points)#
請使用ChatGPT來幫你完成以下任務:
先把上個作業的jsonl檔讀取為pandas dataframe。問ChatGPT時,建議你稍微描述一下,該jsonl檔每列是一個dictionary。
找出來看看有哪些Columns。應該會看到這些
['version', 'canonical_url', 'title', 'author', 'connect_from', 'published_at', 'first_seen_at', 'last_updated_at', 'id', 'producer_id', 'text', 'urls', 'image_urls', 'hashtags', 'keywords', 'tags', 'metadata', 'comments']
Splitting data: 取出所需要的欄位,例如
['title', 'author','published_at','canonical_url']
,然後另存成為一個名為post_df
的dataframe。Splitting data: 取出所需要的欄位,包含
['canonical_url', 'comments']
,另存為一個comment_df
dataframe。注意此時canonical_url
為兩個DataFrame所共通的欄位。目前comments欄位每個Cell裡面應該是一個list-of-dicts,也就是每個Cell有屬於該列的post的多則comments,問ChatGPT如何把他拆成每列剛好一則comments。應該會用到
explode
函式。現在在每列的每則comment是一個
dict
,問ChatGPT要怎麼把這些key-value拆解成dataframe的column和column value。現在你應該會有兩個dataframe,一個是
post_df
,一個是comment_df
。請問該資料集中共包含幾篇貼文、幾篇留言?Post_df和comment_df各有哪些欄位?
# Your code here
Q2. Counting (10 points)#
該資料集中共有幾位貼文者?(注意,可能同一位版友會張貼超過一篇文章)
# Your code here
Q3. Sorting (15 points)#
留言數前十高的留言者是誰?用dataframe的方式印出留言者的暱稱和留言則數。15分
# Your code here
Q4. Sorting (10 points)#
留言數最高的前十篇文章是哪幾篇?各有多少篇留言?用dataframe的方式印出留言者的暱稱和留言則數df.head(10)可以印出前10筆資料。10分
# Your code here
Q5. Timestamp Processing (10 points)#
這是某一天的資料,請問,若把時間拆解成24小時,請依照小時印出每個小時有幾篇貼文。(這題有點難,記得要把相關資料給ChatGPT,他才能幫你拆解)10分
# Your code here
Q6. Summarizing (5 points)#
留言過最多篇貼文的留言者,由高至低排列。注意,留言數最高的人不見得是留言過最多貼文的人,搞不好有人在同一篇貼文有超多留言。
# Your code here
More#
把前十高留言者、留言數最高的前十篇文章用橫向Bar chart繪圖。你可以考慮用plotly、原生的matplotlib、seaborn,但要注意有可能遇到無法處理中文字型的問題,可能要問看看ChatGPT要處理圖表中的中文字型。
# Your code here