Following the timesliderchoropleth tutorial, the code and slider work fine, except for the time-value on top of the map output. It stays at Wed Dec 31 1969 as I slide it. The output map appears to work fine as I see the colours on the choropleth changing. However, in the tutorial, the time-value is supposed to change to reflect the date.
I also noticed that the code below yields a different output in my Jupyter Notebook:
import pandas as pd
n_periods, n_sample = 48, 40
assert n_sample < n_periods
dt_index = pd.date_range(
'2016-1-1', periods=n_periods, freq='M'
).strftime('%s')
dt_index
Output: Tutorial shows the output should be a datetime in seconds format: array(['1454205600', '1456714800', .......1564542000', '1567220400', I am unsure if that issue is related but thought I'd bring it up. Thanks Output of folium version: 0.5.0+105.g065f6f3
array(['2016-01-31 00:00:00', '2016-02-29 00:00:00', '2016-03-31 00:00:00',
'2016-04-30 00:00:00', .......'2019-08-31 00:00:00', '2019-09-30 00:00:00',
'2019-10-31 00:00:00', '2019-11-30 00:00:00', '2019-12-31 00:00:00'],
dtype='
'1569812400', '1572487200', '1575079200', '1577757600'],
dtype='
I was able to reproduce your problem, it also happens outside of Jupyter. You're right about the difference in the values in dt_index, and that's also the problem.
pandas.date_range() returns a DatetimeIndex object. That calls has a strftime method that expects a standard Python datetime formatter, which as far as I know doesn't have a unix timestamp directive. So if using '%s' worked before, it seems undocumented behavior.
A quick solution I found is to convert the DatetimeIndex object to integer values (unix time in nanoseconds) and then to strings:
datetime_index = pd.date_range('2016-1-1', periods=n_periods, freq='M')
dt_index_ints = datetime_index.astype(int) // 10**9
dt_index = dt_index_ints.astype(str)
Can you check if that works for you? Are there other solutions for this?
Amazing. This works perfectly, thank you!
Most helpful comment
I was able to reproduce your problem, it also happens outside of Jupyter. You're right about the difference in the values in
dt_index, and that's also the problem.pandas.date_range()returns aDatetimeIndexobject. That calls has astrftimemethod that expects a standard Python datetime formatter, which as far as I know doesn't have a unix timestamp directive. So if using'%s'worked before, it seems undocumented behavior.A quick solution I found is to convert the
DatetimeIndexobject to integer values (unix time in nanoseconds) and then to strings:Can you check if that works for you? Are there other solutions for this?