Open In App

Create Pandas Series using NumPy functions

Last Updated : 05 May, 2025
Comments
Improve
Suggest changes
1 Like
Like
Report

A Pandas Series is like a one-dimensional array which can store numbers, text or other types of data. NumPy has built-in functions that generate sequences, random values or repeated numbers In this article, we'll learn how to create a Pandas Series using different functions from the NumPy library.

Method 1: Using numpy.linspace()

The linspace() function creates a list of evenly spaced numbers from start to stop with num total values. It's used when you want to divide a range into equal parts.

Output:

Method 2: Using np.random.normal and np.random.rand()

These functions are used when you want to create random test data.

  • random.normal() gives random numbers from a normal distribution. You can set the average, standard deviation and how many values to generate.
  • random.rand gives random numbers between 0 and 1 with a uniform distribution.

Output:

Screenshot-2025-05-04-190727
Using random.normal() and random.rand()

The first output is a single random number from a normal distribution. The second output shows five random float numbers also from a normal distribution. The third output has ten random numbers between 0 and 1 generated from a uniform distribution.

Method 3: Using numpy.repeat()

The numpy.repeat() function repeats a specific value multiple times. It's used when you need to create a Series with the same value repeated.

Output:

ser_using_numpy3
Using repeat method

In the above output we can see that 0.08 is repeating 8 times. With these methods we can easily create pandas series using Numpy.


Next Article

Similar Reads