
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How can series be created using Numpy and passing index value explicitly in Python?
Let us see how a series data structure can be created with the help of a Numpy array, and explicitly giving values for ‘index’.
When no value is specified for index, default values beginning from 0 are assigned to values in the series.
Following is an example −
Example
import pandas as pd import numpy as np my_data = np.array(['ab','bc','cd','de', 'ef', 'fg','gh', 'hi']) my_index = [3, 5, 7, 9, 11, 23, 45, 67] my_series = pd.Series(my_data, index = my_index) print("This is series data structure created using Numpy array and specifying index values") print(my_series)
Output
This is series data structure created using Numpy array and specifying index values 3 ab 5 bc 7 cd 9 de 11 ef 23 fg 45 gh 67 hi dtype: object
Explanation
The required libraries are imported, and given alias names for ease of use.
The next step is to create a numpy array structure.
Next, a list of values that needs to be explicitly specified as index is created.
To the ‘Series’ function present in the ‘pandas’ library, the previously created data and index list is passed as parameters.
The output is displayed on the console.
Note − This indicates that customized values for index can be specified while creating a series data structure.
- Related Articles
- Explain how series data structure in Python can be created using dictionary and explicit index values?
- How can a dataframe be created using a dictionary of Series in Python?
- Explain how series data structure in Python can be created using scalar/constant values?
- How can bubble charts be created using Matplotlib?
- Explain how a dataframe structure can be created using list of dictionary values in Python?
- How can grid plot in Bokeh library be created with Python?
- How can a sequential model be created incrementally with Tensorflow in Python?
- How can a new column be created to a dataframe using the already present columns in Python?
- Can energy be destroyed? Can energy be created ?
- How to access the elements in a series using index values (may or may not be customized) in Python?
- Can we explicitly define datatype in a Python Function?
- What is non-enumerable property in JavaScript and how can it be created?
- Python Pandas - Set index name for an already created Index object
- How many ways a String object can be created in java?
- How many types of JDialog boxes can be created in Java?

Advertisements