Currently, I am using an API to retrieve data about stocks. The data comes in the format:
'Monthly Adjusted Time Series': {'2021-04-21': {'1. open': '238.4700', '2. high': '261.4800', '3. low': '238.0501', '4. close': '260.5800', '5. adjusted close': '260.5800', '6. volume': '352378035', '7. dividend amount': '0.0000'}
and then repeats with new data e.g. 2021-03-21. I then remove the "Monthly Adjusted Time Series" header and send the remaining data to a dictionary as monthly data and define the keys as key_data.
date_list = []
data_list =[]
for data in zip(range(12), keys_data):
data = data[1]
keys_spec = monthly_data[data]
date_list.append(data)
for item in keys_spec:
if item == "1. open":
data_list.append(keys_spec[item])
montly_year_dict = dict(zip(date_list, data_list))
print(montly_year_dict)
This returns the data as following
{'2021-04-21': '238.4700', '2021-03-31': '235.9000', '2021-02-26': '235.0600', '2021-01-29': '222.5300', '2020-12-31': '214.5100', '2020-11-30': '204.2900', '2020-10-30': '213.4900', '2020-09-30': '225.5100', '2020-08-31': '211.5200', '2020-07-31': '203.1400', '2020-06-30': '182.5400', '2020-05-29': '175.8000'
However, I need the data without the quotation marks to use for ChartJs. I've tried several ways through converting into strings, using ast, and splitting the data but nothing has worked thusfar. Is it possible to remove specific characters for a dictionary or is there a better way that doesn't use lists? I am relatively new to python and coding in general so please keep it somewhat simple. Thanks
You might want to concatenate the strings into floats
Here is the documentation I used