When pandas load data from excel, some date columns will load as datetime object.
Excel content:
| date |
count |
| 2019/1/1 |
1 |
| 2019/1/2 |
1 |
| 2019/1/3 |
1 |
| 2019/1/4 |
1 |
| 2019/1/5 |
1 |
| 2019/1/6 |
1 |
pip install pandas openpyxl
import pandas
# from json import dumps
def main():
df = pandas.read_excel('date.xlsx')
print(df)
print(df.dtypes)
# d = dumps(df.to_dict(orient='split')) # will crash and report 'TypeError: Object of type Timestamp is not JSON serializable'
if __name__ == "__main__":
main()
Currently context api use to_json instead of to_dict to avoid this error.
to_json will transform date to epoch milliseconds(default) or ISO8601(iso option) format. The default ISO 8601 format is 2019-01-02T00:00:00.000.
Target:
When
pandasload data from excel, some date columns will load asdatetimeobject.Excel content:
Currently context api use to_json instead of to_dict to avoid this error.
to_jsonwill transform date toepoch milliseconds(default) or ISO8601(isooption) format. The default ISO 8601 format is2019-01-02T00:00:00.000.Target: