# Modifying/extending jsonEncoder for panda dataframe timespan objects

**URL:** <https://community.plotly.com/t/modifying-extending-jsonencoder-for-panda-dataframe-timespan-objects/5179>\
**Category:** Dash Python\
**Created:** [August 1, 2017, 4:38am UTC](https://community.plotly.com/t/modifying-extending-jsonencoder-for-panda-dataframe-timespan-objects/5179 "2017-08-01T04:38:53Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Kcaylor](https://avatars.discourse-cdn.com/v4/letter/k/b3f665/32.png) [@Kcaylor](https://community.plotly.com/u/Kcaylor)\
**Post date:** [August 2, 2017, 5:10pm UTC](https://community.plotly.com/t/modifying-extending-jsonencoder-for-panda-dataframe-timespan-objects/5179/3 "2017-08-02T17:10:26Z")

</div>

Thanks for the response. I did a little digging, and it’s possible to recast `Period` objects in pandas into `Timestamp` objects using the `to_timestamp()` method in `Period`. Once you have a `Timestamp` object, then plotly’s JSON Encoder will do the right thing and use the object’s `isoformat()` method (cf. [PlotlyJSONEncoder.encode\_as\_datetime()](https://github.com/plotly/plotly.py/blob/master/plotly/utils.py#L258).

It looks like the `to_timestamp()` method uses the initial (start) of a `Period` object when building the `Timestamp` object, so `pd.Period('2012-05', freq='D').to_timestamp()` yields `Timestamp('2012-05-01 00:00:00')`, and `PlotlyJSONEncoder().encode(pd.Period('2012-05', freq='D').to_timestamp())` returns `'"2012-05-01"'`.

This seems like the best workaround for now.

---

_[View the full topic](https://community.plotly.com/t/modifying-extending-jsonencoder-for-panda-dataframe-timespan-objects/5179)._
