I'm trying to build a conda panel that can see values based on DatetimeRangeInput slider
so I created dataframe like this
data = {'name':['A', 'B', 'C', 'D'],
'open_time': [dt.datetime(2021, 7, 1, 21, 0), dt.datetime(2021, 7, 2, 11, 0), dt.datetime(2021, 7, 3, 3, 0),dt.datetime(2021, 7, 3, 2, 0) ],
'count':[27, 24, 22, 32],
'size':[34, 56,67,78]
}
df_sample = pd.DataFrame(data)
df_sample
so the output like this
name open_time count size
0 A 2021-07-01 21:00:00 27 34
1 B 2021-07-02 11:00:00 24 56
2 C 2021-07-03 03:00:00 22 67
3 D 2021-07-03 02:00:00 32 78
then added y axis options in this way
yaxis_sample = pn.widgets.RadioButtonGroup(
name='Y axis',
options=['count', 'size'],
button_type='success'
)
widget created like this
date_range = pn.widgets.DateRangeSlider(
name='Date Range',
start=dt.datetime(2021, 7, 1, 00, 00, 00), end=dt.datetime(2021, 8, 1, 00, 00, 00),
value=(dt.datetime(2021, 7, 2, 00, 00, 00), dt.datetime(2021, 7, 4, 00, 00, 00)),
)
date_range
then I'm struggling to combine pipeline and widget, in this section
names = ['A', 'B','C', 'D']
sample_pipeline = (
df[
(date_range.align(df_sample.open_time)) &
(df_sample.name.isin(names))
]
.groupby(['name', 'open_time'])[yaxis_sample].mean()
.to_frame()
.reset_index()
.sort_values(by='open_time')
.reset_index(drop=True)
)
how to check df_sample.open_time
is in the range of date_range.value
?
I've tried following
Attempt 1
names = ['A', 'B','C', 'D']
sample_pipeline = (
df[
(df_sample.open_time >= date_range.param.value_start) & (df_sample.open_time <= date_range.param.value_end) &
(df_sample.name.isin(names))
]
.groupby(['name', 'open_time'])[yaxis_sample].mean()
.to_frame()
.reset_index()
.sort_values(by='open_time')
.reset_index(drop=True)
)
TypeError: Invalid comparison between dtype=datetime64[ns] and Date
Attempt 2
names = ['A', 'B','C', 'D']
sample_pipeline = (
df[
(df_sample.open_time >= date_range.start) & (df_sample.open_time <= date_range.end) &
(df_sample.name.isin(names))
]
.groupby(['name', 'open_time'])[yaxis_sample].mean()
.to_frame()
.reset_index()
.sort_values(by='open_time')
.reset_index(drop=True)
)
IndexingError: Unalignable boolean Series provided as indexer (index of the boolean Series and of the indexed object do not match).