Change language

Creation of a series of pandas

Tags do not have to be unique, but must be hashable. The object supports both integer and label-based indexing and provides many methods for performing index operations. 

Create empty series:
Basic series, which you can create, — this is an Empty Series.

# import pandas as pd

import pandas as pd

 
# Create empty series

ser = pd.Series ()

 

print (ser)

Exit:

 Series ([], dtype: float64) 

Creating a series from an array:
To create a series from an array, we should import the numpy module and use the array () function.

 # import pandas as pd

import pandas as pd

 
# import numpy as np

import numpy as np

 
# simple array

data = np.array ([ ’g’ , ’ e’ , ’e’ , ’k’ , ’ s’ ])

 

ser = pd.Series (data)

print (ser)

Output:

Creating a series from an array with an index:
To create a series from an array with an index, we must provide an index with the same element number as in the array.

# import pandas as pd

import pandas as pd

 
# import numpy as np

import numpy as np

 
# simple array

data = np.array ([ ’g’ , ’e’ , ’ e’ , ’k’ , ’ s’ ])

 
# providing an index

ser = pd.Series (data, index = [ 10 , 11 , 12 , 13 , 14 ])

print (ser)

Output:

import pandas as pd

 
# simple list

list = [ ’g’ , ’ e’ , ’e’ , ’ k’  , ’s’ ]

  
# create series from the list

ser = pd.Series ( list )

print (ser)

Output:


import pandas as pd

 
# simple dictionary

dict = { ’Geeks’ : 10 ,

  ’for’ : 20 ,

  ’ geeks’ : 30 }

 
# create series from dictionary < / code>

ser = pd.Series ( dict )

 

print (ser)

Output:

Create a series from a scalar value:
To create a series from a scalar value, you must specify an index. The scalar value will iterate to match the length of the index.

import pandas as pd

 

import numpy as np

 
# giving a scalar value with an index

ser = pd.Series ( 10 , index = [ 0 , 1 , 2 , 3 , 4 , 5 ])

  

print (ser)

Output:

Creating a series using numpy functions :
To create a series using numpy function, we can use various numpy functions such as numpy.linspace () , randn-python/ target=_blank> numpy.random.radn ( ) .

# import of pandas and nudies

import pandas as pd 

import numpy as np 

  
# NumPy series Linspace ()

ser1 = pd.Series (np. linspace ( 3 , 33 , 3 )) 

print (ser1) 

 
# series with NumPy Linspace ()

ser2 = pd.Series (np.linspace ( 1 , 100 , 10 )) 

print ( "" , ser2) 

Output:

Shop

Gifts for programmers

Learn programming in R: courses

$FREE
Gifts for programmers

Best Python online courses for 2022

$FREE
Gifts for programmers

Best laptop for Fortnite

$399+
Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best computer for crypto mining

$499+
Gifts for programmers

Best laptop for Sims 4

$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically