Pandas DataFrame ‘at’ Keyword.


Pandas DataFrame ‘at’ Keyword.

Table Of Contents:

  1. Syntax For ‘at’ Keyword In Data Frame.
  2. Examples Of ‘at’ Keyword.

(1) Syntax:

pandas.DataFrame.at

Description:

  • Access a single value for a row/column label pair.

Raises

KeyError:
  • If getting a value and ‘label’ does not exist in a DataFrame or Series.

ValueError:

  • If row/column label pair is not a tuple or if any label from

    the pair is not a scalar for DataFrame.

  • If label is list-like (excluding NamedTuple) for Series.

(2) Examples Of ‘at’ Keyword:

Example-1

import pandas as pd
student = {'Name':['Subrat','Abhispa','Arpita','Anuradha','Namita'],
          'Roll_No':[100,101,102,103,104],
          'Subject':['Math','English','Science','History','Commerce'],
          'Mark':[95,88,76,73,93]}
student_object = pd.DataFrame(student)
student_object

Output:

Getting Record At Row ‘1’ And Column ‘Name’

student_object.at[1,'Name']

Output:

'Abhispa'

Example-2

import pandas as pd
student = {'Name':['Subrat','Abhispa','Arpita','Anuradha','Namita'],
          'Roll_No':[100,101,102,103,104],
          'Subject':['Math','English','Science','History','Commerce'],
          'Mark':[95,88,76,73,93]}
student_object = pd.DataFrame(student)
student_object

Output:

Setting Record At Row ‘2’ And Column ‘Name’

student_object.at[2,'Name'] = 'Anuradha'
student_object

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *