Series in Pandas

Series in Pandas is a one-dimensional array, like a column in a table. It is a labeled array that can hold data of any type. The Series() method is used for this and has the following parameters:

  • data: The data to be stored in the Pandas Series
  • index: The index values should have the same length as the data.
  • dtype: It is the datatype for the output Series.
  • name: Set the series name with the name parameter
  • copy: To copy the input data

In this lesson, we will understand what is Series with the following examples:

  • Create a Pandas Series
  • Access a value from a Pandas Series
  • Name your own indexes in a Pandas Series
  • Access a value from a Pandas Series with labels

Create a Pandas Series

To create a series in Python, we use the Series() method. Let us see an example:

Output

The 0,1,2,3, etc. are the index numbers i.e. labels.

Access a value from a Pandas Series

Let us see how to access a specific value from a Series. The [] is used to access a value. Set the index of the value you want to display inside []:

Output

Name your own indexes in a Pandas Series

The index argument is used to set and name your own indexes in a Series i.e. the labels can be set accordingly. Let us see an example:

Output

Access a value from a Pandas Series with labels

If you have set the custom index for labels as shown above, then accessing any value from the Series is quite easy. Refer to the label and that’s it. Let’s see an example:

Output

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others:


For Videos, Join Our YouTube Channel: Join Now


Read More:

DataFrames in Pandas
Read CSV in Python Pandas
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading