- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 the elements in a series using index values (may or may not be customized) in Python?
If default values are used as index values in Series, they can be accessed using indexing. If the index values are customized, they are passed as index values and displayed on the console.
Let us understand it with the help of an example.
import pandas as pd my_data = [34, 56, 78, 90, 123, 45] my_index = ['ab', 'mn' ,'gh','kl', 'wq', 'az'] my_series = pd.Series(my_data, index = my_index) print("The series contains following elements") print(my_series) print("Accessing elements using customized index") print(my_series['mn']) print("Accessing elements using customized index") print(my_series['az'])
The series contains following elements ab 34 mn 56 gh 78 kl 90 wq 123 az 45 dtype: int64 Accessing elements using customized index 56 Accessing elements using customized index 45
The required libraries are imported, and given alias names for ease of use.
A list of data values is created, that is later passed as a parameter to the ‘Series’ function present in the ‘pandas’ library
Next, customized index values (that are passed as parameter later) are stored in a list.
The series is created and index list and data are passed as parameters to it.
The series is printed on the console.
Since the index values are customized, they are used to access the values in the series like series_name[‘index_name’].
It is then printed on the console.
- How to retrieve multiple elements from a series when the index is customized Python?
- Which of the following statements is incorrect for a chemical reaction?Heat may be given out but never absorbed.Sound may be produced.A colour change may take place.A gas may be evolved.
- Sheila's birthday is in May. The date is a multiple of 6 and 9. Can you guess her birthday?a. May 9thb. May 18thc. May 27thd. May 30th
- How to access pandas Series elements using the .iloc attribute?
- How to access pandas Series elements using the .loc attribute?
- Explain how series data structure in Python can be created using dictionary and explicit index values?
- How to access Pandas Series elements by using indexing?
- How to access datetime indexed elements in pandas series?
- Write a program in Python to check if a series contains duplicate elements or not
- Newly formed DNA copies may not be identical at times. Give reason.
- Python - How to access the last element in a Pandas series?
- How can series be created using Numpy and passing index value explicitly in Python?
- Complete the following sentences:Every point on the number line corresponds to a… number which may be either… or ....
- How to get the index and values of series in Pandas?
- How do Mendel’s experiments show that the(a) traits may be dominant or recessive.(b) traits are inherited independently.