- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Explain the different ways in which data from a series data structure can be accessed in Python?
The ability to index elements and access them using their positional index values serves a great purpose when we need to access specific values.
Let us see how series data structure can be index to get value from a specific index.
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("The second element (zero-based indexing)") print(my_series[2]) print("Elements from 2 to the last element are") print(my_series[2:])
Output
The series contains following elements ab 34 mn 56 gh 78 kl 90 wq 123 az 45 dtype: int64 The second element (zero-based indexing) 78 Elements from 2 to the last element are gh 78 kl 90 wq 123 az 45 dtype: int64
Explanation
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 are stored in a list.
A specific index element is accessed from the series using indexing ability of Python.
Python also contains indexing ability, where the operator ‘:’ can be used to specify a range of elements that need to be accessed/displayed.
It is then printed on the console.
- Related Articles
- Explain how the top ‘n’ elements can be accessed from series data structure in Python?
- Explain how the bottom ‘n’ elements can be accessed from series data structure in Python?
- Explain how series data structure in Python can be created using scalar/constant values?
- Explain how series data structure in Python can be created using dictionary and explicit index values?
- What is a series data structure in Pandas library in Python?
- How many ways can a property of a JavaScript object be accessed?
- How many ways can we read data from the keyboard in Java?
- What is data handling? What are the different ways to represent data?
- Deletion from a Max Heap in Data Structure
- Explain linear data structure queue in C language
- How can Bokeh be used to visualize different shapes of data points in Python?
- Rectangle Data in Data Structure
- How can data be summarized in Pandas Python?
- How can BeautifulSoup package be used to parse data from a webpage in Python?
- How can Matplotlib be used to generate time-series data?

Advertisements