キーがdatetime.datetimeの辞書があります。&値はつぶやきのリストです。だから、次のようになります。datetimeオブジェクトのフィルタ日付(月別)
{datetime.datetime(2017, 9, 30, 19, 55, 20) : ['this is some tweet text'],
datetime.datetime(2017, 9, 30, 19, 55, 20) : ['this is another tweet']...
私は年の各月に送出つぶやきの数を取得しようとしています。これまでのところ、私は自分自身
startDate = 10
endDate= 11
start = True
while start:
for k,v in tweetDict.items():
endDate-=1
startDate-=1
datetimeStart = datetime(2017, startDate, 1)
datetimeEnd = datetime(2017,endDate, 1)
print(datetimeStart, datetimeEnd)
if datetimeStart < k < datetimeEnd:
print(v)
if endDate == 2:
start = False
break
ただけプリント(私はprint文を認識してんだ)...
2017-08-01 00:00:00 2017-09-01 00:00:00
2017-07-01 00:00:00 2017-08-01 00:00:00
2017-06-01 00:00:00 2017-07-01 00:00:00
2017-05-01 00:00:00 2017-06-01 00:00:00
2017-04-01 00:00:00 2017-05-01 00:00:00
2017-03-01 00:00:00 2017-04-01 00:00:00
2017-02-01 00:00:00 2017-03-01 00:00:00
2017-01-01 00:00:00 2017-02-01 00:00:00
はなく、実際のつぶやき...持っています。私は何かを期待していた...
2017-08-01 00:00:00 2017-09-01 00:00:00
['heres a tweet']
['theres a tweet']
2017-07-01 00:00:00 2017-08-01 00:00:00
['there only 1 tweet for this month']....
私はこれをどうやって達成できますか?
このインスタンスではgroupbyの方が簡単かもしれませんが、 '(k、v)'の直下のforループの最初の行に 'SyntaxError'が続きます。私はPython 3を使用しています。あなたのコードはPython 2のように見えるので、違いがありますか? – e1v1s
ああ、謝罪、@ e1v1sは 'print x'を' print(x) 'に変更します(私はこのマシンにpython 3をインストールしていません)。 – Bahrom
はい、私は既にprintステートメントの周りにかっこを追加しました。上記のコメントに「構文エラー」が記載されています:) – e1v1s