- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to access a single value in pandas Series using the .at attribute?
The pandas.Series.at attribute is used to access the single labeled element from a Series object and It is very similar to the loc in pandas. The “at” attribute takes label data to get or set the series value in that particular label position.
It will return a single value based on the index label, and it also uploads the data at that particular label position.
Example 1
import pandas as pd # create a sample series s = pd.Series({'A':12,'B':78,"C":56}) print(s) print(s.at['A'])
Explanation
In this following example, we have created a series using a python dictionary and the index will be labeled by using the keys in the dictionary. Here the “A” is a label in s.at['A'] used to represent the positional index of a value.
Output
A 12 B 78 C 56 dtype: int64 Output: 12
We can see both initialized series object and output for at attribute in the above block.
Example 2
import pandas as pd # create a sample series s = pd.Series([2,4,6,8,10]) print(s) s.at[0]
Explanation
We initialized a Series object with no index. If no index is provided, we can consider the index of our series object starting from 0 and increment in steps of 1 up to n-1.
Output
0 2 1 4 2 6 3 8 4 10 dtype: int64
The value present in the positional index “0” is displayed in the above block which is “2”.
Example 3
import pandas as pd # create a sample series s = pd.Series({'A':12,'B':78,"C":56}) print(s) s.at['A'] = 100 print("Updated value at index 'A' ") print(s)
Explanation
Now let’s update the value “100” in the series object using at attribute, which is located at label “A” i,e Index “A”.
Output
A 12 B 78 C 56 dtype: int64 Updated value at index 'A' A 100 B 78 C 56 dtype: int64
We have successfully updated the value “100” at label position “A”, we can see both the series object in the above output block.
- Related Articles
- How to access a single value in pandas Data Frame using the .at attribute?
- How to access a single value in pandas Series using the integer position?
- How to access pandas Series elements using the .iloc attribute?
- How to access pandas Series elements using the .loc attribute?
- How to access a single value in pandas DataFrame using the integer positions?
- How to access a group of elements from pandas Series using the .iloc attribute with slicing object?
- How to access pandas DataFrame elements using the .iloc attribute?
- How to access pandas DataFrame elements using the .loc attribute?
- How to access Pandas Series elements by using indexing?
- Python - How to access the last element in a Pandas series?
- How to access datetime indexed elements in pandas series?
- How to concrete a single Series into a string Python Pandas library?
- Plot multiple time-series DataFrames into a single plot using Pandas (Matplotlib)
- Pandas series Vs. single-column DataFrame
- How to Get the Position of Max Value of a pandas Series?
