Skip to content

Tag: dictionary

KeyError: ‘…’ keeps coming back

I keep getting the error and can’t find where the problem lies. I’m trying so I can choose wether I want the attack the creature or both printed and what type the creature is: ‘easy’, ‘medium’ or ‘hard’, I want to store that into a variable. Thanks in advance An…

How do I fill a dictionary with indices in a for loop?

I have a transposed Dataframe tr: 7128 8719 14051 14636 JDUTC_0 2451957.36 2452149.36 2457243.98 2452531.89 JDUTC_1 2451957.37 2452149.36 2457243.99 2452531.90 JDUTC_2 2451957.37 2452149.36 2457244.00 2452531.91 JDUTC_3 NaN 2452149.36 NaN NaN JDUTC_4 NaN 2452149.36 NaN NaN JDUTC_5 NaN 2452149.36 NaN NaN JDUTC…

How to convert a 5-level dictionary into a DataFrame?

I have a dictionary with structure: Level 1: id (int) username (str) meta (contain a string of Kpi_info) This is a dictionary: My desire result is a DataFame like this: id username Year Month revenue kpi result 206 hantran 2021 1 2000 2100 0 206 hantran 2021 2 2500 2000 1 206 hantran 2022 1 3000 2500 1 206 ha…

how to divide a column element wise in python

I want to divide the first column of this table element wise by 3.6. enter image description here It throws an error something like : Here’s what I tried: Answer There are several ways to do it, here are two. I suggest from your error message that your data is in a pd.DataFrame. I used a shortened versi…

python nested dictionaries from sql queries

Hello i am trying to create a dictionary that would like this I have the following in a db which i am querying i have the following code in order to loop through the query results and create a dictionary but its not creating it like the i am wanting it o Any help would be very much appreciated. Answer

How do I print a dictionary’s keys based on its value?

So, I’ve created a dictionary of key, value pairs for course name and student ID respectively. I want to be able to iterate through the dictionary and print all of the keys (course names) that contain a particular value (student ID). So, here’s the first initialization of variables followed by ask…

Updating A List Word Counter

I’m creating a program that counts letters. I created two dictionaries that both have the same word and, because they are the same exact word, both have the same counter. I want to know how to merge the two dictionaries so that it updates the counters as well, but I consistently receive the result &#822…