Используйте параметр include_lowest=True
в cut
:
df=df.assign(session=pd.cut(df.Time.dt.hour,
[0,6,12,18,23],
labels=['Night','Morning','Afternoon','Evening'],
include_lowest=True))
А затем Series.value_counts
с Series.plot.bar
:
df['session'].value_counts().plot.bar()
Или:
session=pd.cut(df.Time.dt.hour,
[0,6,12,18,23],
labels=['Night','Morning','Afternoon','Evening'],
include_lowest=True)
session.value_counts().plot.bar()
Образец :
rng = pd.date_range('2017-04-03', periods=100, freq='30T')
df = pd.DataFrame({'Time': rng})
#print (df)
session=pd.cut(df.Time.dt.hour,
[0,6,12,18,23],
labels=['Night','Morning','Afternoon','Evening'],
include_lowest=True)
session.value_counts().plot.bar()