- 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
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 −
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)
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
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.
- 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?
- How can grid plot in Bokeh library be created with Python?
- Explain how a dataframe structure can be created using list of dictionary values in 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 we explicitly define datatype in a Python Function?
- How can autoencoder be generated using an encoder and decoder using Python?
- How many ways a String object can be created in java?
- How many types of JDialog boxes can be created in Java?
- How to access the elements in a series using index values (may or may not be customized) in Python?
- How can the preprocessed data be shuffled using Tensorflow and Python?