The Wayback Machine - https://web.archive.org/web/20240213201425/https://www.geeksforgeeks.org/create-pandas-series-using-numpy-functions/
Open In App
Related Articles

Create Pandas Series using NumPy functions

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Pandas Series is a one-dimensional labeled array capable of holding data of any type (integer, string, float, python objects, etc.).

Let’s see how can we create a Pandas Series using different numpy functions.

Code #1: Using numpy.linspace()




# import pandas and numpy
import pandas as pd
import numpy as np
  
# series with numpy linspace() 
ser1 = pd.Series(np.linspace(3, 33, 3))
print(ser1)
  
# series with numpy linspace()
ser2 = pd.Series(np.linspace(1, 100, 10))
print("\n", ser2)
  


Output:

 

Code #2: Using np.random.normal() and random.rand() method.




# import pandas and numpy
import pandas as pd
import numpy as np
  
# series with numpy random.normal
ser3 = pd.Series(np.random.normal())
print(ser3)
  
# series with numpy random.normal
ser4 = pd.Series(np.random.normal(0.0, 1.0, 5))
print("\n", ser4)
  
# series with numpy random.rand
ser5 = pd.Series(np.random.rand(10))
print("\n", ser5)


Output:

 

Code #3: Using numpy.repeat()




# import pandas and numpy
import pandas as pd
import numpy as np
  
  
# series with numpy random.repeat
ser = pd.Series(np.repeat(0.08, 7))
print("\n", ser)


Output:


Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills and become a part of the hottest trend in the 21st century.

Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.


Last Updated : 18 Dec, 2018
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials