Label Not In List and KeyError

Viewed 18965

I'm trying to get the value of a specific cell.

  main_id   name  code
  0    1345  Jones    32
  1    1543   Jack    62
  2    9874   Buck    86
  3    2456   Slim    94

I want the cell that says code=94, as I already know the main_id but nothing else.

raw_data = {'main_id': ['1345', '1543', '9874', '2456'],
        'name': ['Jones', 'Jack', 'Buck', 'Slim'],
        'code': [32, 62, 86, 94]}

    df=pd.DataFrame(raw_data, columns = ['main_id', 'name', 'code'])


    v=df.loc[str(df['main_id']) == str(2456)]['code'].values
    print(df.loc['name'])

The print(df.loc['name']) claims the label is not in index

And the v=df.loc[str(df['main_id']) == str(2456)]['code'].values says 'KeyError False'

2 Answers
Related