我有一个包含各种格式时间戳的数据帧。
print df.head()
Time _datetime time_stamp hour day
0 00:00:00.0000000 1486339200000 2017-02-06 00:00:00 0 Monday
1 00:00:00.0000000 1486339200000 2017-02-06 00:00:00 0 Monday
2 00:00:00.0000000 1486339200000 2017-02-06 00:00:00 0 Monday
3 23:59:59.0000000 1486339199000 2017-02-05 23:59:59 23 Sunday
4 23:59:59.0000000 1486339199000 2017-02-05 23:59:59 23 Sunday
Time object
_datetime int64
time_stamp datetime64[ns]
hour int64
day object
我希望绘制密度图:
p = ggplot(aes(x='_datetime'),data=df) + geom_density()
这很有效。但是,当我添加颜色分解时:
p = ggplot(aes(x='_datetime',color='day'),data=df) + geom_density()
我明白了:
numpy.linalg.linalg.LinAlgError: singular matrix
我试过了:
p = ggplot(aes(x='time_stamp',color='day'),data=df) + geom_density()
返回TypeError: invalid type promotion
这可能与Plotting event density in Python with ggplot and pandas
有关编辑
如果我将day
从对象更改为int
:
df['day'] = df['time_stamp'].dt.weekday
p = ggplot(aes(x='_datetime',color='day'),data=df) + geom_density()
它返回:
ValueError: RGBA sequence should have length 3 or 4