Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

1 import requests

2 import pandas as pd
3
4 # link for Bitcoin Data
5 link =
"https://min-api.cryptocompare.com/data/histoday?fsym=BTC&tsym=USD&limit=365&aggregate=1"
6
7 # API request historical
8 historical_get = requests.get(link)
9
10 # access the content of historical api request
11 historical_json = historical_get.json()
12
13 # extract json data as dictionary
14 historical_dict = historical_json['Data']
15
16 # extract Final historical df
17 df = pd.DataFrame(historical_dict,
18 columns=['close', 'high', 'low', 'open', 'time',
'volumefrom', 'volumeto'],
19 dtype='float64')
20
21 # time column is converted to "YYYY-mm-dd hh:mm:ss" ("%Y-%m-%d %H:%M:%S")
22 posix_time = pd.to_datetime(df['time'], unit='s')
23
24 # append posix_time
25 df.insert(0, "Date", posix_time)
26
27 # drop unix time stamp
28 df.drop("time", axis = 1, inplace = True)
29

You might also like