1,186 questions
1
vote
1
answer
64
views
KeyError when trying to access Symbol columns from NASDAQ Other Symbols FTP export
I am trying to make a program to get a list of all (or at least almost all) USA listed stocks on all exchanges. I got AI to generate the following program suggestion:
import pandas as pd
from ftplib ...
0
votes
2
answers
171
views
How do I access specific keys and values from CSV files?
I have a CSV file keeping track of people's score in a game. I read it with csv.DictReader().
How do I create a dictionary with the keys being the names and the value being the scores?
CSV file ...
1
vote
1
answer
146
views
Advice on how to handle KeyError occurring when using map Lambda and slicing for dictionary lookup
I'm creating a lookup table / dictionary from a static spreadsheet for upcoming labelling on input data, adding a new field for flavor:
lookup_table_data = pd.read_csv(r'C:\Location\format1.csv', sep='...
1
vote
2
answers
55
views
How can I calculate averages and min max values in a climate data frame after Creating an Index on Date-time in Pandas
I have climate data dataframe in cs format but no headers, so I read data as follows:
df_MERRA_data = pd.read_csv(fname,delimiter=',',header=None)
df_MERRA_data.columns = \
['Date-time'...
0
votes
1
answer
29
views
KeyError using Astropy .differentials code
I keep getting KeyError: 'd_ρ' on my d_rho = ... line. I am trying to run the differentials so that I can put them in a table column (or single column per variable), to use for calculating velocity. ...
0
votes
1
answer
162
views
KeyError: 'self' in save_hyperparameters() when custom metaclass used - Pytorch Lightning
Description
I'm working with LightningDataModule and wanted to ensure that a method (_after_init) runs only once after full initialization, regardless of subclassing. For that, I implemented a custom ...
0
votes
1
answer
31
views
return self._engine.get_loc(casted_key) error when in for loop, same code runs with no error outside of the loop
I have a very simple for loop which was working last week but when I run it this week on exactly the same data it is not working... when I run the code outside of the loop it works without an error. I ...
1
vote
1
answer
96
views
Locals() strange behaviour python?
Why does this not work ?
Python 3.11.6 (main, Oct 8 2023, 05:06:43) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more ...
1
vote
1
answer
58
views
get data from dataframe with pandas module
import pandas
data = pandas.read_csv("databooks.csv")
print(data.titulo)
All ok , but:
print(data.autor)
KeyError: 'autor'
autor exists and is well written
I expected the autor column ...
1
vote
1
answer
78
views
Getting KeyError when Python iterates through Excel named ranges
I have a Python script which iterates through a set of Excel named ranges (DT_1, DT_2, ... DT_30). All ranges are in the same workbook, same sheet and are all named systematically. The script saves ...
2
votes
1
answer
74
views
Why are enums incompatible across python packages?
An enum is declared in an imported package and identically in the importer. Same value, but Python treats the imported enum value as different for some reason. Package 1 is a parser that I wrote which ...
0
votes
1
answer
37
views
Flask Session persistent KeyError
I'm building a simple webshop where products in basket are stored in the session dictionary before the user registered (after the information is stored in SQL). The error-handling is not delivering ...
0
votes
0
answers
27
views
Troubleshooting Model File Loading Issues
"I’m encountering this error in my PythonAnywhere application when trying to read my training files and use them in the final stage. I've repeatedly updated libraries and corrected paths, but the ...
0
votes
1
answer
254
views
Magic line %sql [duplicate]
I am trying to run an SQL statement in Jupyter using the magic line %sql:
%load_ext sql
%sql sqlite:///FinalDB.db
%sql SELECT COUNT(*) FROM TABLE2
but I receive a KeyError: 'DEFAULT'
I wonder what ...
0
votes
0
answers
54
views
getting an error when trying to duplicate table with DML
I was trying to duplicate data from an existing table to an empty table in different schema (all in the same database) and got an error. (PostgreSQL 16):
This is for specific exercise, so I have to ...
0
votes
1
answer
80
views
Keyerror while accessing environment variable in AKS pod
My Python script uses environment variables, the environment variables are set by Azure configmap, and they are accessible from pod command prompt. They are also available to Python when I run ...
1
vote
1
answer
52
views
column is not accessible using groupby and apply(lambda)
I'm encountering a KeyError when trying to use the .apply() method on a pandas DataFrame after performing a groupby. The goal is to calculate the weighted average baced on the Industry_adjusted_return ...
0
votes
1
answer
84
views
A python pulp problem about KeyError(0,0,0)
I tried to use pulp to create a decision variable x with 3 dimesions.Then I defined a objective function. However the pulp showed
P[j] * min(D[j], pl.lpSum(x[i, j, t] * Y[i, j] for i in fields)) - pl....
-1
votes
1
answer
80
views
How to avoid "key error" in python for loop? [duplicate]
I am new to python and I am trying to conduct multiple PubMed searches and save the number of results in a CSV file. The code I have right now will not run uless I remove my for loop. I would like the ...
0
votes
1
answer
534
views
KeyError: 'temperature' in DSPy ChainOfThought()
I created a custom LM Client class like this
from dsp import LM
import json
class CustomLMClient(LM):
def __init__(self, model, **kwargs):
self.model = model
self.provider = "...
0
votes
1
answer
189
views
KeyError when trying to get variables' values using globals()
I'm writing a simple mod for a Ren'Py game (to show "hidden" variables).
Information about such variables is kept in a lists of dictionaries; like this (simplified):
icm_data_rowan = [
{
...
0
votes
2
answers
136
views
Pandas: KeyError using df.loc with condition
Using the following program which selects the rows with numbers included in 'Num' in a DataFrame.
import pandas as pd
data = {'Num': [[1,2,100], [10,20,30], [1,2,30],[1,2,200],[4,0,9]],'Id':range(5)}
...
0
votes
1
answer
59
views
Is there a parameter problem, or not working with this method?
I wanted to predict the disease type using a function with a given string parameter. The parameter can contain more than one string. But it always gives an error message: KeyError: 'skin_rash'
This is ...
0
votes
0
answers
570
views
KeyError: 'st.secrets has no key "password"
I want to use streamlit secrets for easy access to my streamlit-app via password. I feel like I did everything as described in the documentation.
Streamlit-Doc
But I keep receiving the following Error-...
-2
votes
2
answers
180
views
Keyerror: 0 in Python 3.12
I'm new to python and I'm programming the Blackjack game in python with a friend of mine. I'm getting Keyerror:0 on this lines:
card1=random.choice(cards)
card2=random.choice(cards)
Is it a writing ...
0
votes
0
answers
33
views
LookupError: No plugin named 'GremlinPlugin'
neo4j version 2.3.1, py2neo version 2.0.8, jdk 1.8, python 3.4. The Gremlin service was successfully installed. However, when running the project, it still shows that the plug-in cannot be found:
I ...
0
votes
2
answers
1k
views
Python how to solve KeyError: 2
So I am doing a problem in Codehs and I have run into a error for one of the problems. I am not very good at programming but I cannot figure out what I have done wrong. I keep getting the KeyError: 2 ...
0
votes
1
answer
101
views
Flask KeyError or return None
I am a beginner learning python flask web development. I am currently migrating my program to the web space, but I ran into a problem.
My problem is that when you click on the "Check Price" ...
0
votes
1
answer
47
views
Python Kivy KeyError with kwargs
I am writing a program to calculate paces for different track events and I am trying to set a variable that represents the event that the user chose to calculate.
Below is the section of the .py file
...
0
votes
0
answers
50
views
Ignore or replace 'KeyError' in 'csv_file.writerow' - Python
I am working on a Python script that pulls data from an API, turns it to a JSON then goes through and writes a row to a CSV file for a small database, it writes a new row for each of the devices in ...
0
votes
1
answer
535
views
KeyError when accessing Streamlit session_state in Python script despite initializing session_state variable
I'm encountering a KeyError when trying to access Streamlit's session_state in my Python script, despite initializing the session_state variable. Here's my code:
import streamlit as st
def main():
...
1
vote
3
answers
57
views
Pandas First Value That Doesnt Return KeyError
I have a dataframe that has either column A or B
I was hoping for a syntax that uses the or operator to have a stntax like:
Value = df.at['Total','A'] or df.at['Total','B']
but I still receive a ...
0
votes
1
answer
168
views
Why hasattr gives KeyError?
chat = await Chat.objects.aget(chatid = chatid)
if hasattr(chat, 'agent') and 'active' in chat.status:
await asyncio.sleep(5)
This code throws KeyError: 'agent'.
In Python 3 hasattr uses try-...
-1
votes
1
answer
59
views
Python string.format KeyError with variable key
I'm pulling in text strings with placeholders for instance attributes. I'm trying to write something that will get the place holder text, find the attribute with that name, and swap it in. I'm able to ...
0
votes
0
answers
94
views
KeyError: 'stock_move_id'
I'm trying to update a custom module in Odoo14 whereby I want to introduce a new field or column in the account.move module that tells me which stock.move movement ID, if any, each line in account....
0
votes
0
answers
93
views
KeyError in text generator
I'm trying to write code that will collect statistics on the sequence of characters in the text and generate new text based on it. This works when collecting statistics with one character, but as soon ...
0
votes
0
answers
76
views
Python nested loop issue
Im trying to compare two sets of coordinates in to dataframes using nested for loops. Where distance is less than a predefined value, I want to overwrite the coordinates in the qinsy_file_2. If they ...
3
votes
1
answer
281
views
KeyError despite adding dependency
I've recently installed the Insurance Management module and I'm trying to enhance its functionality. My goal is to add a page in the CRM lead notebook to display insurances created for each lead.
...
0
votes
1
answer
272
views
Unable to fetch the data using column name from pandas dataframe after assigning a column name
I have created a pandas dataframe from an API endpoint. I have used the following to convert to a df.
df = pd.json_normalize(js.loads(js.dumps(key_value))
This however does create df as required but ...
5
votes
2
answers
8k
views
Input to ChatPromptTemplate is missing variables {'input', 'agent_scratchpad'}. Expected: ['agent_scratchpad', 'input']
This code gives me an weird error:
from langchain_core.output_parsers import StrOutputParser
from langchain_core.runnables import RunnableLambda, RunnablePassthrough
def create_weaviate_new_RAG(...
1
vote
0
answers
114
views
Key error in a column of a csv file with pandas
I was making a code in python to put the data in a column of a csv file with pandas but when I ran it it gave me a KeyError. The code is this:
import pandas as pd
df = pd.read_csv('archivos\\hi.csv')
...
0
votes
1
answer
76
views
How to extract error data from KeyError in python
I have an excel file from which I retrieve data with pandas. I have a dictionary where keys are the same strings that I get from a cell from the excel file. For example, I have a excel cell that ...
-2
votes
1
answer
245
views
Key error in python/pygame (code was working fine before) [duplicate]
I'm using python 3.12, and keep getting this error message when I try to run my code:
KeyError: 0
The above exception was the direct cause of the following exception:
Traceback (most recent call last)...
-1
votes
1
answer
80
views
im getting a keyerror when trying to access a dictionary where the key does exist
I'm building this app where I can see live cricket scores using this API. When I'm trying to access the teams name its giving me a key error which doesn't make sense as the key does exist.
import ...
-1
votes
1
answer
160
views
Using the PykTok module on a EC2 instance
I'm trying to use the PykTok module on an ec2 instance. It's set up to work (I've the right versions of everything)
When I execute my script I got this error :
KeyError: 'DBUS_SESSION_BUS_ADDRESS'. ...
2
votes
2
answers
382
views
KeyError when applying with_columns iteratively over different columns when using pl.struct on Polars LazyFrame
I have the following issue with Polars's LazyFrame "Structs" (pl.struct) and "apply" (a.k.a. map_elements) in with_columns
The idea here is trying to apply a custom logic to a ...
0
votes
0
answers
45
views
I'm getting keyerror in python . "Exception has occurred: KeyError 'labels'"
In my python program I'm getting this error:
Exception has occurred: KeyError
'labels'
KeyError: 'labels'
I'm getting error from this code:
labels = data['labels'].reshape(-1).astype(np.int32)
Can ...
-1
votes
1
answer
222
views
LinearRegression model gives me keyError 0
I have written some code for a linear regression model to predict house prices. I'm witting exactly the same as a tutorial video; when I write random_state=42 it works without any error, but when I ...
0
votes
0
answers
2k
views
KeyError at / 'daily'
current_weather_url =
'https://api.openweathermap.org/data/2.5/weather?q={}&appid={}'
forecast_url =
'https://api.openweathermap.org/data/3.0/onecall?lat={}&lon={}&exclude=current,minutely,...
-2
votes
1
answer
136
views
KeyError in Python though the key exists in dictionary [duplicate]
I am solving a leetcode problem 17. Letter Combinations of a Phone Number. I have coded this solution using Python3.
class Solution:
def letterCombinations(self, digits: str) -> List[str]:
...