'Using crypto compare API and wrapper, when it outputs the "time" its in an indecipherable format. How do I change it?
from datetime import datetime
crypto_list = cryptocompare.get_historical_price_hour('ETH', 'USD', limit=24, exchange='CCCAGG', toTs=datetime.datetime.now())
crypto_prices = pd.DataFrame(crypto_list, columns=['time', 'open', 'close', 'volumeto']).set_index('time')
When I run this code, it works, but the "time" makes no sense. They're 24 long integers. How do I convert it to a date or datetime? I've tried all the code to convert datetime to hour or whatever, but it says can't convert int to datetime. For example, one of the "dates" is 1648785600
Solution 1:[1]
You need to convert epoch time to pd.datetime.
crypto_prices.reset_index(inplace=True)
crypto_prices['time'] = pd.to_datetime(crypto_prices['time'],unit='s')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | KVEER |
