0

Im new to python and I would like to make my time column a readable date time format. My end goal is too pull yearly data for a crypto and only using Daily closes.

Kinda having trouble defining my Time column properly to transform it.

import pandas as pd

import requests
import json
import datetime
url = 'https://api.kucoin.com'


kline = requests.get(url + '/api/v1/market/candles?                type=1min&symbol=BTC-USDT&startAt=1566703297&endAt=1566789757')
kline = kline.json()
kline = pd.DataFrame(kline['data'])
kline = kline.rename({0:"Time",1:"Open",
            2:"Close",3:"High",4:"Low",5:"Amount",6:"Volume"},   axis='columns')

kline.set_index('Time', inplace=True)
kline.head()
FObersteiner
  • 22,500
  • 8
  • 42
  • 72
Jimmy6In
  • 1
  • 4
  • Does this answer your question? [Converting unix timestamp string to readable date](https://stackoverflow.com/questions/3682748/converting-unix-timestamp-string-to-readable-date) – FObersteiner Apr 20 '22 at 06:05

1 Answers1

0

You can use pd.to_datetime with unit argument

kline = kline.rename({0:"Time",1:"Open",
                      2:"Close",3:"High",
                      4:"Low",5:"Amount",6:"Volume"}, axis='columns')

kline['Time'] = pd.to_datetime(kline['Time'], unit='s')
# ^^^  Addition here

kline.set_index('Time', inplace=True)
Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52