So this is my first time using pandas and the only info i can find other than unrelated issues here is in the documentation and ive read it over several times and im not sure what im doing wrong my attempt is to pull user info from a CSV file and the current program im using to figure it out simply prints the collected data but every time i run the program it pops a KeyError but my column names are number based with names and user IDs in the table but whether its a string or integer it says the same KeyError(1).
(sensitive information removed or replaced)
input:
(ID: 1 | RID: 2)
`
import pandas as pd
import numpy as np
UDS = pd.read_csv("AEAUserData.csv")
df = pd.Series(["0", "1", "2", "3"], index=["0", "1", "2", "3"])
ID = input("Enter User ID: ")
RID = input("Enter receiving ID: ")
UNN = ""
PWN = ""
acitveUN = UDS.at[int(ID), 1]
activePW = UDS.at[ID, 4]
activeUS = UDS.at[ID, 2]
activeENC = UDS.at[ID, 5]
receivingUN = UDS.at[RID, 1]
receivingPW = UDS.at[RID, 4]
receivingUS = UDS.at[RID, 2]
receivingENC = UDS.at[RID, 5]
/*
commence printing everything
*`
(AEAUserData.csv)
0,1, 2, 3, 4, 5, 6,
1,FamFighter123,Lt. Dan,5,Password123,Soaring Eagle,
2,BubbaShrimp123,Gen. Bubba,3,Password456,Shrimp Boat,
3,1Forest1,Pfc. Gump,2,Password789,Life is like a box of chocolates,
Output:
`Enter User ID: 1
Enter receiving ID: 2
Traceback (most recent call last):
File “C:Users**********AppDataLocalPackagesPythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0LocalCachelocal-packagesPython312site-packagespandascoreindexesbase.py”, line 3805, in get_loc
return self._engine.get_loc(casted_key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “index.pyx”, line 167, in pandas._libs.index.IndexEngine.get_loc
File “index.pyx”, line 196, in pandas._libs.index.IndexEngine.get_loc
File “pandas_libshashtable_class_helper.pxi”, line 7081, in pandas._libs.hashtable.PyObjectHashTable.get_item
File “pandas_libshashtable_class_helper.pxi”, line 7089, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 1
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “C:Users*Desktop**Debug_Tester.py”, line 9, in
acitveUN = UDS.at[int(ID), 1]
~~~~~~^^^^^^^^^^^^
File “C:Users*AppDataLocalPackagesPythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0LocalCachelocal-packagesPython312site-packagespandascoreindexing.py”, line 2575, in getitem
return super().getitem(key)
^^^^^^^^^^^^^^^^^^^^^^^^
File “C:Users*AppDataLocalPackagesPythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0LocalCachelocal-packagesPython312site-packagespandascoreindexing.py”, line 2527, in getitem
return self.obj._get_value(key, takeable=self._takeable)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:Users*AppDataLocalPackagesPythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0LocalCachelocal-packagesPython312site-packagespandascoreframe.py”, line 4214, in _get_value
series = self._get_item_cache(col)
^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:Users*AppDataLocalPackagesPythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0LocalCachelocal-packagesPython312site-packagespandascoreframe.py”, line 4638, in _get_item_cache
loc = self.columns.get_loc(item)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:Users*AppDataLocalPackagesPythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0LocalCachelocal-packagesPython312site-packagespandascoreindexesbase.py”, line 3812, in get_loc
raise KeyError(key) from err
KeyError: 1`
I’ve tried changing the ranges which brings up other errors and reading the documentation maybe I’m illiterate but I couldn’t find why this was happening other than I didn’t make the dataframe correctly.
YAAT MAN is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.