Pandas Dataframe issue on engine.get_loc #19466
-
If I comment on this one, df = df[~df['Name'].isin(['A'])], the entire code will work. I am trying to understand issue over there, so df['Compare'][a] == 'True', 'a' as 0,1,2,3, this format is not recommend ? --------------------------------------------Error Message------------------------------------------------------ KeyError Traceback (most recent call last) File /lib/python3.10/site-packages/pandas/_libs/index.pyx:136, in pandas._libs.index.IndexEngine.get_loc() File /lib/python3.10/site-packages/pandas/_libs/index.pyx:163, in pandas._libs.index.IndexEngine.get_loc() File pandas/_libs/hashtable_class_helper.pxi:2131, in pandas._libs.hashtable.Int64HashTable.get_item() File pandas/_libs/hashtable_class_helper.pxi:2140, in pandas._libs.hashtable.Int64HashTable.get_item() KeyError: 0 The above exception was the direct cause of the following exception: KeyError Traceback (most recent call last) File /lib/python3.10/site-packages/pandas/core/series.py:958, in Series.getitem(self, key) --------------------------------------------Code------------------------------------------------------ df = pd.DataFrame({"Name":["A","B","B","C"], df['Compare'] = (df['Name'] == df['Str']) df = df[~df['Name'].isin(['A'])] for a in range(len(df)): print(df) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
NVM,I figure it out. df = df[~df['Name'].isin(['A'])] print(df.iloc[:,3])for a in range(len(df)): df |
Beta Was this translation helpful? Give feedback.
NVM,I figure it out.
df = df[~df['Name'].isin(['A'])]
print(df.iloc[:,3])
for a in range(len(df)):
if df.iloc[a,3] == 'True':
# df['output'][a] = (df['Size'][a],df['Compare'][a])
df.iloc[a,4] = (df.iloc[a,2],df.iloc[a,3])
df