Creating Series from list, dictionary, and numpy array 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. In this article, we will see various ways of creating a series using different data types.

Creating Series from list 

The list of some values form the series of that values uses list index as series index.

Python

filter_none

edit
close

play_arrow

link
brightness_4
code

# import pandas as pd
import pandas as pd
  
# simple list
lst = ['G','E','E','K','S','F',
       'O','R','G','E','E','K','S']
  
# forming series
s = pd.Series(lst)
  
# output
print(s)

chevron_right


Output :

0     G
1     E
2     E
3     K
4     S
5     F
6     O
7     R
8     G
9     E
10    E
11    K
12    S
dtype: object

Creating Series from dictionary

Dictionary of some key and value pair for the series of values taking keys as index of series.



Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# import pandas as pd
import pandas as pd
  
# simple dict
dct = {'G':2,'E':4,'K':2,'S':2,
       'F':1,'O':1,'R':1}
  
# forming series
s = pd.Series(dct)
  
# output
print(s)

chevron_right


Output :

G    2
E    4
K    2
S    2
F    1
O    1
R    1
dtype: int64

Creating Series from Numpy array

The 1-D Numpy array  of some values form the series of that values uses array index as series index.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# import pandas as pd
import pandas as pd
  
# import numpy as np
import numpy as np
  
# numpy array
arr = np.array(['G','E','E','K','S','F',
                'O','R','G','E','E','K','S'])
  
# forming series
s = pd.Series(arr)
  
# output
print(s)

chevron_right


Output :

0     G
1     E
2     E
3     K
4     S
5     F
6     O
7     R
8     G
9     E
10    E
11    K
12    S
dtype: object



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.