'Plot Investpy Data in Highchart/Highstocs

I've been experimenting some problems while trying to plot Mutual Funds data extracted from Investpy API onto a Highchart graph, into QT View (in Python)

Here's the call to the API and the plot, the problem is I want to add the Date of each value on the X axis but I'm not able to. Some ideas?

# Fetch Data of specific Fund -> JSON style
data = investpy.funds.get_fund_historical_data(
        fund=name ,
        country=country,
        from_date='01/04/2000',
        to_date='13/05/2022',
        as_json=True
        )

 H = Highchart()
 H.add_data_set(data['Open'], series_type='line', name='VL')
 options = { .. . . . . . }
 H.set_dict_options(options)

 # "Embed" the graph into the QT Python view via WebEngineWidget
 view.browser = QtWebEngineWidgets.QWebEngineView(view)
 view.browser.setHtml(H.htmlcontent)
 view.layout.addWidget(view.browser)

The problem is that I need to get a JSON file instead of XML from Investpy in order to be able to plot the HTML content (Highchart.htmlcontent) but I don't know how to correctly set data to the highchart.

Data Structure received from Investpy:                                                     
   Date (index)      Open      ....     Close    
      (date)      (double)     ....   (double)

(Index Column must be the Date (plotted in xAxis) and I only need the 'Open' value to plot

The error I get is on add_data_set(data['Open']) -> (obviously : string indices must be integers) That works well If I choose the XML way, but then, in H.htmlcontent it fails because it doesn't have a JSON serializable object. Some ideas?



Solution 1:[1]

You need to put the input into the while and then only when the loop is over calculate the average
Like this:

num = int(input("enter numbers and then -1 to stop: "))
num_count = 1
sum = num
while num!=-1:
    num = int(input("another number: "))
    num_count+=1
    sum+=num
print(sum/num_count)

Solution 2:[2]

In order for it to work you need to add an input() call inside the while loop like in the code bellow :

count = 0
sum = 0
num = int(input('''please enter any number of your choice\n
please enter -1 to stop entry and run program\n'''))

while num != -1:
    sum += num
    count +=1
    num = int(input('''Give another integer\n'''))


print("the average of the numbers you have entered is", sum/count)

Personal advice : I would suggest for you to read more tutorials or ask your peofessor for more work

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 S H
Solution 2 Vaggelis_Lazarakis