这周我决定去熊猫馆玩一玩。我有一个包含历史IRC日志的pandas数据框,如下所示:
timestamp action nick message
2005-11-04 01:44:33 False hack-cclub lex, hey!
2005-11-04 01:44:43 False hack-cclub lol, yea thats broke
2005-11-04 01:44:56 False lex Slashdot - Updated 2005-11-04 00:23:00 | Micro...
2005-11-04 01:44:56 False hack-cclub lex slashdot
2005-11-04 01:45:12 False lex port 666 is doom - doom Id Software (or mdqs o..
2005-11-04 01:45:12 False hack-cclub lex, port 666
2005-11-04 01:45:21 False hitokiri lex, port 23485
2005-11-04 01:45:45 False hitokiri lex, port 1024
2005-11-04 01:45:46 True hack-cclub slaps lex around with a wet fish
大约有5.5万行,我正在尝试做一些基本的可视化,比如排名前25位的缺口等等。我知道我可以像这样得到前25个刻痕:
^{pr2}$我要的是滚动计数:
hack-cclub lex hitokiri
1 0 0
2 0 0
2 1 0
3 1 0
3 2 0
4 2 0
4 2 1
4 2 2
5 2 2
这样我就可以为前25个缺口绘制一个从时间开始的信息区域图。我知道我可以通过迭代整个数据帧并保持计数来做到这一点,但由于这样做的全部目的是学习使用pandas,所以我希望有一种更为惯用的方法来实现这一点。如果有相同的数据,但使用等级而不是像这样的运行计数,也会很好:
hack-cclub lex hitokiri
1 2 2
1 2 2
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
1 2 2
1 2 2
你需要^{} 和{a2}:
相关问题 更多 >
编程相关推荐