使用 ggplot 和 pandas 在 Python 中绘制事件密度

2024-03-27

我正在尝试可视化这种形式的数据:

  timestamp               senderId
0     735217  106758968942084595234
1     735217  114647222927547413607
2     735217  106758968942084595234
3     735217  106758968942084595234
4     735217  114647222927547413607
5     etc...

geom_density如果我不分开就可以senderIds:

df = pd.read_pickle('data.pkl')
df.columns = ['timestamp', 'senderId']
plot = ggplot(aes(x='timestamp'), data=df) + geom_density()
print plot

结果看起来符合预期:

但是如果我想展示senderId分别,正如文档中所做的那样 http://ggplot.yhathq.com/docs/geom_density.html, 它失败:

> plot = ggplot(aes(x='timestamp', color='senderId'), data=df) + geom_density()
ValueError: `dataset` input should have multiple elements.

尝试使用更大的数据集(约 40K 事件):

> plot = ggplot(aes(x='timestamp', color='senderId'), data=df) + geom_density()
numpy.linalg.linalg.LinAlgError: singular matrix

任何想法?对于这些错误,有一些答案,但似乎没有一个相关。

这是我想要的图表(来自 ggplot 的文档):


对于较小的数据集:

> plot = ggplot(aes(x='timestamp', color='senderId'), data=df) + geom_density()
ValueError: `dataset` input should have multiple elements.

这是因为一些senderIds 只有一排。

使用更大的数据集:

> plot = ggplot(aes(x='timestamp', color='senderId'), data=df) + geom_density()
numpy.linalg.linalg.LinAlgError: singular matrix

这是因为对于某些人来说senderId我有多行完全相同timestamp。不支持此功能ggplot。我可以通过使用更精细的时间戳来解决它。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 ggplot 和 pandas 在 Python 中绘制事件密度 的相关文章

随机推荐