TypeError: ‘>=’ not supported between instances of ‘datetime.date’ and ‘str’

My code
import dash
import dash_table as dt
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
import pandas as pd
import plotly.graph_objects as go
from dash.dependencies import Input, Output
from datetime import date

df=pd.read_csv(‘Jan-21.csv’)
df_product=df.groupby([‘BILL_DATE’,‘DEPARTMENT’]).sum().reset_index()
df_product[‘NETAMT’]=round(df_product[‘NETAMT’],2)
df_product[‘BILL_DATE’]=pd.to_datetime(df_product[‘BILL_DATE’])
df_product[‘BILLDATE’]=df_product[‘BILL_DATE’].dt.date
df_product.set_index(‘BILLDATE’)
print(df_product[:5])

app = dash.Dash(name)

app.layout = html.Div([
dcc.DatePickerRange(
id=‘my-date-picker-range’,
reopen_calendar_on_clear=True,
clearable = True,
min_date_allowed=date(2021,1,1),
max_date_allowed=date(2021,1,31),
initial_visible_month=date(2021,1,1),
end_date=date(2021,1,31)
),
dt.DataTable(id=‘my-table’,
columns=[{‘name’:i,‘id’:i} for i in df_product],
data=df_product.to_dict(‘records’),
page_current=0,
page_size=15,
style_data_conditional=[
{
‘if’: {‘row_index’: ‘odd’},
‘backgroundColor’: ‘rgb(248, 248, 248)’
}
],
style_header={
‘backgroundColor’: ‘rgb(230, 230, 230)’,
‘fontWeight’: ‘bold’
}
)
])

@app.callback(
Output(‘my-table’, ‘data’),
[Input(‘my-date-picker-range’, ‘start_date’),
Input(‘my-date-picker-range’, ‘end_date’)]
)

def update_output(start_date, end_date):
dff = df_product[‘BILLDATE’].between(start_date,end_date)
print(start_date)
print(end_date)
data=dff.to_dict(‘records’)
print(data[:5])
return data

if name == ‘main’:
app.run_server(debug=False)
teatv.ltd net banking

Hi @paulvijayji,
It might help if you post the data frame information df.info() and a sample of your dataset in order for the community to be able to help.

Hi @paulvijayji

What the error message is saying is that you cant make comparisons between different type of element, in this case you are trying to compare a datetime element with a string element.

you need first to convert the string into datatime.

PD: a tip to share code in the forum:

image