:::| 目前位置圖示目前位置:首頁圖示回首頁 | 主功能頁圖示相關問答
查詢對應的資料

[日期]:2018/06/04  [瀏覽人數]:396

#ans 為用pandas匯入的Answers.csv
#qst 為用pandas匯入的Questions.csv

Answers Index(['Id', 'OwnerUserId', 'CreationDate', 'ParentId', 'Score','IsAcceptedAnswer', 'Body'], dtype='object')
Questions Index(['Id', 'OwnerUserId', 'CreationDate', 'Score', 'Title', 'Body'], dtype='object')
問題回答Answers的ParentID對應問題Questions的ID欄位,
若要以Answers讀入為主,再由Answers讀入時取得Questions的Body內容時可用以下方法:
for icnt in range(0,len(ans)):
#取得Answers的ParentId找出Questions的內容Body
qstbody = qst[qst['Id'].isin([ans['ParentId'][icnt]])]['Body'].values
print(qstbody[0],ans["Body"][icnt])