- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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.
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) print("Elements from 2 to the last element are") print(my_series[2:])
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
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.
- 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?
- What are the document properties which can be accessed using Legacy DOM?
- Explain linear data structure queue in C language
- Rectangle Data in Data Structure
- Which of the following areas data mining technology can be applied?
- How many ways can we read data from the keyboard in Java?
- Deletion from a Max Heap in Data Structure
- How can data be summarized in Pandas Python?
- How can Matplotlib be used to generate time-series data?
- What are the different ways the transaction can be executed(DBMS)?