我有一个时间戳数据点的json文件,需要一个直方图显示每单位时间的数据点数。数据采用以下格式:
database = {
"data": [
{
"timestamp": "Mon Aug 01 00:00:01 +0000 1901",
"user": 796327373691985921,
"text": "blah blah there were no tweets in 1901!?!",
"polarity": 0.2,
"subjectivity": 0.2
},
{
"timestamp": "Mon Aug 01 00:00:10 +0000 1901",
"user": 16548385,
"text": "blah blah blah"
"polarity": 0.0,
"subjectivity": 0.0
}
]
}
等等
我无法从字典中选择时间戳项。例如,当我运行它:print(database [“data”] [0] [“timestamp”]时,它为我提供了一个数据点的时间戳,但是如何根据时间戳将所有推文组织成时间段?我怀疑需要迭代循环,但我不知道如何继续。再次感谢你!
1)将您的时间戳转换为从一天开始以来的秒数(也许使用datetime.timedelta
)。
2)现在,创建具有固定bin边缘的直方图:
edges = list(range(0, 24 * 3600, 3600))
plt.hist(data, edges)