/  Technology   /  Python program to get Length, Size and Shape of a Series
pandas-exercises (i2tutorials)

Python program to get Length, Size and Shape of a Series

What is Series in Pandas?

Pandas Series is a one-dimensional labeled array capable of holding data of any type (integer, string, float, python objects, etc.). The axis labels are collectively called index. Pandas Series is nothing but a column in an excel sheet.

How do we get Length, Size, and Shape of a Series?

Below are the steps to write the python program in a series

Step 1: We have to import Pandas and below is the code shown how it is imported.

import pandas as pd

Step 2: Import a CSV file from the local directory which contains the data

We have to use the method as pd.read_csv which means we are asking pandas to read the csv file which has been imported from local directory

In the next line, we read the data into “furniture” variable and execute

Furniture=pd.read_csv('C:/Users/LENOVO/Desktop/Furniture.csv')
Furniture

Output:

  Serial          Product   Brand   Cost
0       1         sofa set     Jay  35000
1       2         side bed   Akhil  50000
2       3  nightstand lamp  Harsha  11000
3       4     coffee table   Bindu  19000
4       5         wall art   Divya   7777

As series is a one-dimensional array with only one column of data from data frame can be used.

Here, let us convert the dataframe column into series.

series_var=pd.Series(Furniture[‘Product’])

len: we will use this to understand the length of the series

len(series_var)

output:

5

size: we will use this to understand the size of the series

series_var.size

output:

5

Shape: we will use this to understand the shape of the series

series_var.shape

output:

(5,)

Leave a comment