You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.rst
+34
Original file line number
Diff line number
Diff line change
@@ -329,6 +329,40 @@ Hello World, and Basic Usage
329
329
href='https://www.highchartspython.com')
330
330
my_chart.options.credits = my_credits
331
331
332
+
# EXAMPLE 3.
333
+
# Pandas with timeseries
334
+
import pandas as pd
335
+
import datetime as dt
336
+
import numpy as np
337
+
df = pd.DataFrame([
338
+
{"ref_date": dt.date(2024, 1, 1), "data": 1},
339
+
{"ref_date": dt.date(2024, 1, 2), "data": 5},
340
+
{"ref_date": dt.date(2024, 1, 3), "data": None},
341
+
{"ref_date": dt.date(2024, 1, 4), "data": 4},
342
+
{"ref_date": dt.date(2024, 1, 5), "data": None},
343
+
])
344
+
345
+
df['ref_date'] = pd.to_datetime(df['ref_date'])
346
+
df.set_index('ref_date', inplace=True)
347
+
df.index = (df.index.astype(np.int64) /10**6).astype(np.int64) # Correcting nanoseconds to epoch, this is crucial for javascript rendering, check https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now for more information on this behaviour
Normally, in the context of pandas one would reference their pandas DataFrame with the timeseries at the index.
504
+
505
+
Beware that javascript renders time through epoch, and so does the Highcharts javascript library, thus keep in mind this is a requirement!
506
+
507
+
For further read on the top, check the example under `Date.now() - JavaScript | MDN <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now>`__,
508
+
also try playing with your browser console and use something like `Date.now();`, and you should see a very large int represeting the current time in epoch, meaning the time elapsed since 1970, January the first in nanoseconds.
0 commit comments