Python Forum
Issue accessing data from Dictionary/List in the right format
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue accessing data from Dictionary/List in the right format
#2
Your server function get_weather_data returns a dict whose keys point to two lists, one with strings ('time') and another with numbers ('temp'). When I try to reproduce your code:

>>> temp_data = {'time':['2020-07-23 12:00:00', '2020-07-23 15:00:00', '2020-07-23 18:00:00'], 'temp':[8.81, 7.15, 5.83]}

>>> x = [n['time'] for n in temp_data]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: string indices must be integers, not str

>>> [type(n) for n in temp_data]
[<type 'str'>, <type 'str'>]

>>>
Because temp_data is the one variable that links to a dict and can be invoked with keys, what happens if you change the line in red with this one:

self.plot_4.data = go.Scatter(x=[n for n in self.temp_data['time']],
y=[n for n in self.temp_data['temp']],
line=dict(color='#2196f3')
Reply


Messages In This Thread
RE: Issue accessing data from Dictionary/List in the right format - by eismb - Jul-24-2020, 01:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort a list of dictionaries by the only dictionary key Calab 2 652 Apr-29-2024, 04:38 PM
Last Post: Calab
  Help with to check an Input list data with a data read from an external source sacharyya 3 478 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  Matching Data - Help - Dictionary manuel174102 1 430 Feb-02-2024, 04:47 PM
Last Post: deanhystad
  List Comprehension Issue johnywhy 5 604 Jan-14-2024, 07:58 AM
Last Post: Pedroski55
  Dictionary in a list bashage 2 608 Dec-27-2023, 04:04 PM
Last Post: deanhystad
  filtering a list of dictionary as per given criteria jss 5 758 Dec-23-2023, 08:47 AM
Last Post: Gribouillis
  Export data from PDF as tabular format zinho 5 775 Nov-11-2023, 08:23 AM
Last Post: Pedroski55
  How to add list to dictionary? Kull_Khan 3 1,056 Apr-04-2023, 08:35 AM
Last Post: ClaytonMorrison
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 1,959 Dec-12-2022, 08:22 PM
Last Post: jh67
  Issue in writing sql data into csv for decimal value to scientific notation mg24 8 3,138 Dec-06-2022, 11:09 AM
Last Post: mg24

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020