✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚾️ It's finally Baseball season! Root for the home team... & Register for our Sports Analytics Webinar!

Date range slider

Hi there , I have a data frame which contains date format like this('01-january-2016 to 01-august-2018) ,the interval is one month , I want a date range slider I have tried it but don’t know where I am wrong ,below is my code

import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd

df = pd.read_csv(‘C://Users//PycharmProjects//app1//Book1.csv’)

app = dash.Dash()

app.layout = html.Div([
marks={str(oDateID): str(oDateID) for oDateID in df[‘oDateID’].unique()},

if name == ‘main’:

the oDateID is the column name , can anyone help me out with this?

I am not 100% sure how pandas are handling dates but:
It looks like your dates are in a string format and you are asking for the minimum and maximum value of these which does not make any sense. Asking for the maximum in a list of strings is like asking a book for its maximum word.
You need to convert your dates into some kind of number (try and look up pythons Datetime library), sort it, then convert it back again to strings.

I was just having a similar problem, and was going to post if anyone knows the answer.

I think there could be two problems.

One problem as mentioned by Blaceus, is that your datetimes are not being imported as datetimes. There’s a parsedates argument in read_csv you can try. Also you could try saving your data as a feather file, which will preserve the datetime format.

The other problem I think is that the rangeslider and slider components don’t support datetime formats. But I’m not 100% sure about this. I tested it and couldn’t get it working with datetime formats, but who knows, maybe I was doing something wrong.

You might have to index your data with just plain numbers.

There’s also this post here, but it wasn’t super clear the answer which solved it.

what if the date format is like 2018-2-11