0
私は、コメント(文字列テキスト)に関する情報とコメントが投稿された日付を含むタプルのリストを持っています。たとえば:タプルのリストからdfへのデータfrom
comments[1]
(datetime.date(2016, 8, 29),
'I played with these ATM before but they are just too expensive way to buy bitcoins.There were a few in the city I live but many of them already stop operation, most likely because no one actually uses them.')
私はtopic
は1〜40の数であり、タプル(topic, value)
のリストを返す機能lda_description
を持っており、返されるリストの長さも1および40から例えば次のとおりです。
lda_description(comments[1][1])
[(10, 0.43287377217078077), (14, 0.43712141484779793), (21, 0.068338146314754045)]
問題があります私はlda_description
の検索結果をpandasデータフレームにマップし、40列のトピックを持ち、インデックスはdatetimeです。データフレームフィールド値は、特定の日付に各トピックのすべてのコメント 'lda_description
の合計である必要があります。
は、私は私の意見では効率的ではなく、多分誰かがで私を助けることができるソリューションを持っているこの:)
#Creating empty dataframe
df = pd.DataFrame(0, index=pd.date_range(datetime.datetime(2013,12,1), datetime.datetime(2016,11,21)).tolist(),
columns=range(1,41))
df["count"] = 0
i = 0
for com in comments:
if i % 50000 == 0:
print(datetime.datetime.now(), i)
i += 1
topic_dist = lda_description(com[1])
for dist in topic_dist:
df.set_value(com[0],dist[0],
df.ix[com[0]][dist[0]] + dist[1])
df.set_value(com[0],'count',
df.ix[com[0]]['count'] + 1)