def get_comment_product_fea(endtime):
enddt = pd.to_datetime(endtime,format = '%Y-%m-%d')
if enddt == pd.to_datetime('2016-04-15',format = '%Y-%m-%d'):
commentdata = pd.read_csv(FilePath + CommentFile)
commentdata = commentdata[(commentdata["dt"] == "2016-04-15")]
commentdata = commentdata.sort_values(by="sku_id").reset_index()[["sku_id", "comment_num", "has_bad_comment", "bad_comment_rate"]]
return commentdata
else:
startdt = enddt - pd.Timedelta(days=7)
commentpath = FilePath + CommentFile
commentdata_ALL = pd.read_csv(commentpath) # ?Jdatya_comment.csv??????
commentdata_ALL.dt = pd.to_datetime(commentdata_ALL.dt, format='%Y-%m-%d') # ?dt????date??
comment = commentdata_ALL[(commentdata_ALL.dt <= enddt) & (commentdata_ALL.dt > startdt)]
df = pd.get_dummies(comment['comment_num'], prefix='comment_num')
comment = pd.concat([comment, df], axis=1)
comment = comment[['sku_id', 'has_bad_comment', 'bad_comment_rate', 'comment_num_1', 'comment_num_2', 'comment_num_3','comment_num_4']]
sorted_comment = comment.sort_values(by=['sku_id']).reset_index().drop('index',1)
#sorted_comment.to_csv(FilePath + 'skuFeaInComment_before'+str(enddt), index=False)
return sorted_comment
# ????????
评论列表
文章目录