gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 19:11:03 25 4
gpt4 key购买 nike

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

  timestamp               senderId
0 735217 106758968942084595234
1 735217 114647222927547413607
2 735217 106758968942084595234
3 735217 106758968942084595234
4 735217 114647222927547413607
5 etc...
如果我不分隔 senderId

geom_density 会起作用:

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

结果符合预期:

density plot

但是,如果我想单独显示 senderIdas is done in the doc , 它失败了:

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

尝试使用更大的数据集(约 4 万个事件):

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

有什么想法吗?对于这些错误,SO 上有一些答案,但似乎都不相关。

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

density plot

最佳答案

使用较小的数据集:

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

这是因为一些 senderId 只有一行。

有了更大的数据集:

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

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

关于python - 使用 ggplot 和 pandas 在 Python 中绘制事件密度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40101519/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com