Questions tagged [keyerror]

In languages such as Python and Ruby, a KeyError is a specific exception type that is raised when a key could not be found within a dictionary (mapping). In Python, it is a subclass of LookupError. In Ruby, it is a subclass of IndexError.

Filter by
Sorted by
Tagged with
0 votes
0 answers
11 views

In Python 3.8.8, why does read_csv(StringIO()) behavior change depending on where the string is populated and passed to the function?

Depending on whether I declare a string variable within a function, or pass it from outside the function, changes the behavior of the function. Specifically, declaring a string variable and converting ...
user22616636's user avatar
0 votes
0 answers
21 views

How to fix "instagrapi" python library error?

I get outputted a "KeyError" and I don't what's provoking it My code: " from instagrapi import Client with open("credentials.txt", "r") as f: username, password ...
11chat's user avatar
  • 1
1 vote
1 answer
39 views

Pandas upgrade from 1.5.3 to 2.1 returns key error on df.sum() even though key does exist

I recently upgraded pandas 1.5.3 to 2.1. I didn't change any code and a previous df.["Total"].sum() given below which previously ran fine now returns a key error on the word "Total&...
CreditcruncherX's user avatar
0 votes
0 answers
8 views

KeyError: 20908 when tyring to fine-tune bert model

I'm trying to do fine-tune bert model with custom dataset . and this error occured while training model. i have no idea why this error occured please help class DataLoader(Dataset): ""&...
SUHYEONHAN's user avatar
1 vote
1 answer
73 views

how to handle KeyError: 'choices' with chatGPT?

i have an interface for chatgpt which usually works, but randomly seems to come up with a KeyError that i currently cannot resolve or avoid. it uses the solara library to create a web page from the ...
cameronmg-j's user avatar
1 vote
0 answers
24 views

KeyError on importing from a irrelevant function in the same file

Traceback (most recent call last): File "/Users/sergioleylanguren/Desktop/Route Decider/routelookup/app.py", line 7, in <module> from config import init_config File "/...
Sergio Ley's user avatar
0 votes
1 answer
13 views

Key Error while trying to fetch data from API

I have used below mentioned code to fetch data from Intune warehouse, but faced an error as attached: #pip install requests pandas plotly import requests import pandas as pd import plotly....
Jalapu Mahipal Reddy's user avatar
-2 votes
3 answers
68 views

Key error when I try to iterate on dictionary [closed]

I have the file text.txt with following data Oscar Morera 90 Maria Esquivel 95 Lucia Benavides 80 Javier Miranda 85 Alonso Gonzalez 75 I tried to run a code to copy and sum the ...
Oscar Morera's user avatar
0 votes
1 answer
40 views

"num_pixels" gives keyError for regionprops_table in scikit-image as property

import skimage import numpy as np array = np.array(([1,1],[1,0])) skimage.measure.regionprops_table(array, properties=("num_pixels", "area_filled")) gives keyError for "...
Václav Bočan's user avatar
1 vote
0 answers
23 views

Pandas KeyError in Kaggle set

I am new to pandas and manipulated some internet code to work with this dataset. I made minor adjustments to the dataset (broke down pressure to two columns, rename headers, etc) and spend some ...
Skar's user avatar
  • 11
0 votes
0 answers
47 views

Python KeyError problem when loading the saved model in pytorch

I am new to deep learning. I am using a transformer model for bengali language stemming process. Now, I trainied the model and test it with some data and it worked fine. So i saved the model. But when ...
Mahir RAfid's user avatar
0 votes
1 answer
46 views

MLPRegressor result

This is an example of a book that I can't figure out or make it work. Other cases I could solve but it became a challenge. When I run it, it shows me this message: Paste complete output: Traceback (...
Mauricio Luis Vega's user avatar
2 votes
1 answer
46 views

Pandas : KeyError due to datetime column

In a script, I consider a subset (of rows) of a pandas dataframe, do some operations on it and assign back to the whole dataframe. But in some cases, the subset is actually the dataframe itself, and ...
Lainv's user avatar
  • 21
-1 votes
2 answers
46 views

how to return a string if the dictionary value is an integer in Python

When I comment on all the key - values in my_dict, I should be given the last line, return 'No distance info to available', but it gives me an error my_dict = { # "distance": 500.5, #...
egrqX's user avatar
  • 11
0 votes
1 answer
73 views

Why does an error occur saying st.session_state has no key "new_todo" in streamlit

I am following a course and which created this program (The course was Python Mega Course: Learn Python in 60 days, Build 20 apps). When I run the program using streamlit run web.py it says I didn't ...
Aditya Singh's user avatar
0 votes
0 answers
7 views

is there anything i can add to my code to avoid this key error

col_dict = {'Life_expectancy':1,'Adult_mortality':2,'Infant_deaths':3,'Alcohol':4,'Percentage_expenditure':5,'HepatitisB':6,'Measles':7,'BMI':8,'Under_five_deaths':9,'Polio':10,'Total_expenditure':11,'...
KIRTHIGAA .S btech_ai2020's user avatar
0 votes
1 answer
227 views

Odoo V15, 500: Internal Server Error after move to new server | UserError: The attachment is colliding with an existing file

As first, thank you for help me, i am beginner in Odoo Website. Since i have move on proxmox the website Odoo V15 to new Proxmox (same Website), the website shows me 500: Internal Server Error. Befor ...
Pascal Ottiger's user avatar
0 votes
2 answers
34 views

Key Error in Pandas while copying a column to new dataframe

I am trying to create a new column in a dataframe based on another existing column in the same dataframe and then copy the new column to a different dataframe. df1['column1'] = '' df1.loc[df['column2']...
sk8's user avatar
  • 180
-1 votes
1 answer
41 views

Discord.py Python Program Returning KeyError

I have recently been working on a python project with programming a discord bot. First I will post my Main.py file, then the error I was having: import configparser import os import discord from ...
Josh's user avatar
  • 11
0 votes
2 answers
31 views

Word 2Vec pretrained embedding KeyError with Gensim==4

I'm traying to use a pretrained word2vec model for Arabic language the code suppose to be written as following unknownArray=[] # load the whole embedding into memory w2v_embeddings_index={} ...
Arwa Ahmed's user avatar
0 votes
0 answers
15 views

I am facing this error while started evaluation/training: _3d_result = torch.load(path[0])[0] KeyError: 0

I am facing error in this piece of code: for fusion_input,tensor_index,path in tqdm(val_data) fusion_input = fusion_input.cuda() tensor_index = tensor_index.reshape(-1,2) tensor_index = ...
Muhammad Adeel Altaf's user avatar
0 votes
0 answers
30 views

KeyError: 'receiver' in self.scope[]

I am trying to retrieve data through self.scope[] in Django channels but I keep getting KeyError. How can I get the receiver part through self.receiver_username without the error? See the code details ...
Dorcas Ogidan's user avatar
0 votes
1 answer
38 views

Tkinter callback KeyError in Listbox

I am trying to write code that will make it easier for my colleagues to follow several aspects of our IT policies. Part of the code will deal with backing up files. I have code that enables people add ...
Herwin's user avatar
  • 1
0 votes
1 answer
13 views

KeyError.gnuhealth.inpatient.registration

I am using Tryton's GNU Health. I am facing a KeyError exception for the "gnuhealth.inpatient.registration" model in health module when I try to run the module. Others modules run fine, e.g. ...
Muhammad shafi's user avatar
1 vote
2 answers
46 views

Cannot find key in imported dataframe despite the key being present

I have a panel dataset about the Internet Penetration Rate of 11 countries and I want to encode the Country values. Country Year Int Pen Rate % GDP Per Capita GDP Growth % 0 Australia 2014 ...
Sinestro101's user avatar
0 votes
0 answers
89 views

KeyError - Looking for a value in a list

I'm capturing a value from a primary table to apply as a variable later, using this code: #capturing value of the month month = str(DF['COLUMN'].max())[6:7] #reading the xlsx where I want to look for ...
karolyna's user avatar
0 votes
0 answers
156 views

How to solve this Keyerror - Colab

I really need help to solve this problem! KeyError Traceback (most recent call last) /usr/local/lib/python3.10/dist-packages/pandas/core/indexes/base.py in get_loc(...
dorism's user avatar
  • 1
1 vote
1 answer
48 views

Why am I getting a key error with d.get() if that is supposed to be impossible?

I am using Python 3.7.0. When I run the following code, I get the error listed below: import requests url = f'https://statsapi.mlb.com/api/v1/schedule?sportId=1&hydrate=probablePitcher&...
Peter Ohaver's user avatar
0 votes
0 answers
31 views

Error: None of [Index(['..'], dtype='object')] are in the [index]

I have a dataframe with the following results (this is a snippet of the dataframe relevant to my question). researchAndDevelopment operatingExpenses ... depreciationAndAmortization \ 0 ...
Tony's user avatar
  • 13
0 votes
1 answer
36 views

(KeyError) I want to make an application using models and ModelForm structure in Django but I am getting keyerror error

I'm trying to make an electrical formula calculation app in Django. I want to enter the values ​​in the variables in the calculation page and see them on the results page. In doing so, I want the ...
David D's user avatar
-2 votes
1 answer
37 views

Roboflow - Deploy to Luxonis OAK code provided by Roboflow does not work

I already tested all the depthai demos listed on https://docs.luxonis.com/en/latest/#demo-script) on my OAK device. Every demo is working fine but when I’m using the Luxonis OAK code provided by ...
Gerald's user avatar
  • 1
0 votes
0 answers
23 views

setting new column labeled with range in dataframe

from tensorflow import keras import pandas as pd df=pd.read_csv('/Salary_Data.csv',header=None) ============================================= I want to make a new column of dataframe called highincome ...
오상윤's user avatar
-1 votes
2 answers
60 views

Leet Code 242. Valid Anagram KeyError: u'a'

I'm doing Leet Code 242: Valid Anagram. I'm looking at a NeetCode solution from Youtube. I'm trying to run and see what happened in the following code: class Solution(object): def isAnagram(self, ...
zzzprograming's user avatar
0 votes
2 answers
171 views

Unexpected Python KeyError python

I have loaded a CSV file import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from scipy.stats import norm This data will then be loaded data = pd.read_csv('...
RISWAN AZHARI's user avatar
2 votes
1 answer
101 views

i have an error in my python code key error ['logo_url'] not in index

def update_data(n, val): # inpur parameter(s) if n == None: return "Hey there! Please enter a legitimate stock code to get details.", "https://melmagazine.com/wp-content/...
Suhail Khan's user avatar
0 votes
1 answer
45 views

Why does my Flask app search results page need to be reloaded to display results only when served by nginx?

I have set up a flask-based site that takes user input and makes a query to a postgres database. It works great when I run the app locally, but when I take it live on my vps, the search results in an ...
Logos Masters's user avatar
0 votes
1 answer
117 views

Django KeyError at forms.py

I'm learning django and I'm playing around with forms and registering users. When I submit the registration form with the username, email, password, and confirm password fields filled, I get an error ...
rolyjin's user avatar
0 votes
1 answer
140 views

Key exists in dict, but still reporting a KeyError

I found a strange error in Python. The key exists in the dict, but it's still reporting a KeyError. The key exists in list(dict), but key does not exist in dict, why? This is the code: check_key = (...
Isaac's user avatar
  • 17
0 votes
0 answers
132 views

How to solve the key error problem in pandas library in jupyter notebook?

`When I write this code in jupyter notebook for data analysis of housing datasets using pandas and it does not run the code as the error occur. Code: strat_train_set = housing.iloc[train_index] ...
Nida_'s user avatar
  • 1
0 votes
0 answers
27 views

Key errors on this code, included errors at the bottom

from google.colab import files uploaded = files.upload() import pandas as pd import numpy as np df = pd.read_csv("Student-Grades.csv") df.head(5) for i in range(len(df)): df['final ...
Khadijah Muhammad's user avatar
2 votes
0 answers
3k views

If we have a listlike key, _check_indexing_error will raise

This Code is not running,How can I fix it? correlations_data = data.corr()['score'].sort_values() correlations_data It is showing this kind of error, KeyError Traceback (most recent call last) /usr/...
Muna's user avatar
  • 21
0 votes
1 answer
59 views

Key Error in Python when using tuples. But when I print, I see it in the keys

I am trying to write an algorithm for Loopy Belief Propagation. I am using Numpy and pGMpy. The goal is to first initialize messages from nodes to factor. Then at each iteration, you will calculate ...
dlu's user avatar
  • 13
0 votes
0 answers
29 views

Error on Python - Pandas, in the creation of a table

I want to create a table with a dictionary with brands and followers attributes. But I recive the error KeyError: "[...] not in the index" And I don't know how to fix it This is my code: ...
Giacomo Guidi's user avatar
1 vote
0 answers
80 views

KeyError while printing trace in pymc3

I'm trying to perform the spectral unmixing technique with the MCMC algorithm. But I encountered a problem while I ran it. This is the part of the code I'm running: import pymc3 as pm import theano....
Alex's user avatar
  • 11
0 votes
1 answer
319 views

KeyError when using pd.read_csv in pandas [closed]

I am trying to read my csv file but KeyError occurs I can say for sure that column is exactly called 'TG', but for some unknow reason pandas can't read it How can I fix that? import pandas as pd ...
Karambombom's user avatar
0 votes
0 answers
248 views

How to solve KeyError in python?

I am fine tuning a HG model on my own data. I get this error which I can not find the solution. Traceback (most recent call last): File "c:/Users/neg97727/ownCloud/Negin_Master_Thesis/thesis/...
negin madani's user avatar
0 votes
1 answer
48 views

Python: KeyError When Searching by a Value in One Column in Another Column That Has The Values Contained Between # Signs

I am trying to find if values in one column (Column_A) are contained in another column (Column_B) that have values that are separated by # signs. Then I would like to return the matching value in a ...
Brandon's user avatar
  • 99
0 votes
0 answers
59 views

I am getting a keyError when using Alpha Vantage API to get Stochastic Oscillator data for an algorithmic trader

I am using the Alpha Vantage API to get Stochastic Oscillator data to build an algorithmic trader, but I get a keyError when trying to pull the values for NFLX from the Alpha Vantage API This is the ...
HemilT's user avatar
  • 1
0 votes
1 answer
36 views

Why KeyError exception getting thrown even though I'm catching it using try catch

Here's the code class FancyTuple: mapping = {1:"first", 2:"second", 3:"third", 4:"fourth", 5:"fifth"} reverseMapping = {"first": 1, &...
Sairam Tabibu's user avatar
-1 votes
1 answer
54 views

Nested Dictionaries returning KeyError when using .items() in a for loop

I am using nested/embedded dictionaries as I have large quantity of information that I am working with. I was trying to get .items() to work for a smaller example of what I am doing. In the example I ...
Sophia Lopez's user avatar

1
2 3 4 5
24