1

I have a dataframe with a range of different format time stamps.

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

I wish to plot a density plot:

p = ggplot(aes(x='_datetime'),data=df) + geom_density()

This works. However, when I add in a colour dissaggregation:

p = ggplot(aes(x='_datetime',color='day'),data=df) + geom_density()

I get:

numpy.linalg.linalg.LinAlgError: singular matrix

I have tried:

p = ggplot(aes(x='time_stamp',color='day'),data=df) + geom_density()

Returning TypeError: invalid type promotion

This could be related to Plotting event density in Python with ggplot and pandas

Edit If I change day from an object to an int:

df['day'] = df['time_stamp'].dt.weekday

p = ggplot(aes(x='_datetime',color='day'),data=df) + geom_density()

It returns:

ValueError: RGBA sequence should have length 3 or 4

Community
  • 1
  • 1
LearningSlowly
  • 8,641
  • 19
  • 55
  • 78

0 Answers0