- Related Questions & Answers
- What happens if the specified index is not present in the series Python Pandas?
- Explain the different ways in which data from a series data structure can be accessed in Python?
- Python program to compare two Pandas series
- What is an array data structure in Java?
- Accessing elements of a Pandas Series
- How to sort a Pandas Series?
- Data analysis using Python Pandas
- How to plot arbitrary markers on a Pandas data series using Matplotlib?
- Print the mean of a Pandas series
- What is a structure in C#?
- Explain how series data structure in Python can be created using scalar/constant values?
- Construct a DataFrame in Pandas using string data in Python
- Write a Python code to concatenate two Pandas series into a single series without repeating the index
- How to append elements to a Pandas series?
- How can data be summarized in Pandas Python?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Series is a one-dimensional, labelled data structure present in the Pandas library. The axis label is collectively known as index.

Series structure can store any type of data such as integer, float, string, python objects, and so on. It can be created using an array, a dictionary or a constant value.

Let us see how an empty series can be created in Python −

import pandas as pd my_series = pd.Series() print("This is an empty series data structure") print(my_series)

This is an empty series data structure Series([], dtype: float64)

In the above code, ‘pandas’ library is imported and given an alias name as ‘pd’.

Next, series data structure is created by calling the ‘Series’ function.

It is then printed on the console.

Let us see how a series data structure can be created using array, without explicitly naming the index values.

import pandas as pd import numpy as np my_data = np.array(['ab','bc','cd','de', 'ef', 'fg','gh', 'hi']) my_series = pd.Series(my_data) print("This is series data structure created using Numpy array") print(my_series)

This is series data structure created using Numpy array 0 ab 1 bc 2 cd 3 de 4 ef 5 fg 6 gh 7 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 and passing values into it as data.

Next, an empty series data structure is created, and the previously created data is passed as a parameter to it.

The output is displayed on the console.

**Note** − When no values are given for index, default values from 0 are assigned to it.

Advertisements