to_excel incorrectly sets time to midnight for exported datetime column · Issue #9139 · pandas-dev/pandas (original) (raw)
Hello,
I try this:
import requests
from pandas.io.json import json_normalize
import json
import pandas as pd
response = requests.get("http://api.openweathermap.org/data/2.5/history/station?start=1356220800&end=1356307200&type=hour&id=5530")
df = json_normalize(json.loads(response.text)['list'])
df['dt'] = pd.to_datetime(df['dt'], unit='s')
#df = df.set_index('dt')
print(df)
df.to_excel("out.xls")
It displays:
dt humidity.c ... pressure.v temp.c temp.ma \
0 2012-12-23 00:00:00 2 ... 1017.0 2 286.15
1 2012-12-23 01:00:00 2 ... 1017.0 2 286.15
2 2012-12-23 02:00:00 2 ... 1017.0 2 285.15
3 2012-12-23 03:00:00 2 ... 1017.0 2 284.15
4 2012-12-23 04:00:00 2 ... 1017.0 2 283.15
...
19 2012-12-23 19:00:00 1 ... 1016.0 1 282.15
20 2012-12-23 20:00:00 1 ... 1015.0 1 281.15
21 2012-12-23 21:00:00 1 ... 1015.0 1 282.15
22 2012-12-23 22:00:00 1 ... 1015.0 1 281.15
23 2012-12-23 23:00:00 1 ... 1005.0 1 286.15
24 2012-12-24 00:00:00 2 ... 1013.5 2 280.15
but if we look at Excel file dt
column looks like
dt
2012-12-23 00:00:00
2012-12-23 00:00:00
2012-12-23 00:00:00
2012-12-23 00:00:00
2012-12-23 00:00:00
...
2012-12-23 00:00:00
2012-12-23 00:00:00
2012-12-23 00:00:00
2012-12-23 00:00:00
2012-12-24 00:00:00
to_csv
method is ok
In [1]: pd.__version__
Out[1]: '0.15.2'
Kind regards