Reputation: 928
I have the following input /output but the last output is not the expected. I would the timestamp to give the current date but it seems that the conversion change the decimal of the time in the datetime. Any help would be appreciated.
code:
used_list['expiration_timestamp'] = (used_list['expiration_timestamp']/1000)
input:
0 1.584605e+09
1 1.593158e+09
2 1.601021e+09
3 1.601021e+09
4 1.584518e+09
...
165 1.584691e+09
166 1.584691e+09
167 1.601021e+09
168 1.584605e+09
169 1.601021e+09
code2:
used_list['expiration_timestamp'] = pd.to_datetime(used_list['expiration_timestamp'])
output:
0 1970-01-01 00:00:01.584604800
1 1970-01-01 00:00:01.593158400
2 1970-01-01 00:00:01.601020800
3 1970-01-01 00:00:01.601020800
4 1970-01-01 00:00:01.584518400
...
165 1970-01-01 00:00:01.584691200
166 1970-01-01 00:00:01.584691200
167 1970-01-01 00:00:01.601020800
168 1970-01-01 00:00:01.584604800
169 1970-01-01 00:00:01.601020800
EXPECTED OUTPUT 1st row:
0 03/19/2020
Upvotes: 0
Views: 55
Reputation: 114068
pandas by default expects nanoseconds when using numbers to dates (I think)
try
pd.to_datetime(used_list['expiration_timestamp'],unit="s")
to tell pandas its actually seconds
Upvotes: 1