Pandas module in Python provides two data structures, namely Series and Data Frame. While a Data Frame is a tabular dataset has similar mechanism like a spreadsheet, a Series is just a one-dimensional data object with labels. Creating a Series can come from manually input values, with pd.Series() functio, or by inputting a Numpy array with the same function, because Pandas module builds upon Numpy. Next example shows creating a Series from simple array of 4 elements.
#Import Pandas and Numpy module
import pandas as pd
import numpy as np
#create an array from Numpy
TA = np.array([32, 19, 301, 7])
TA
#output
array([ 32, 19, 301, 7])
#create a Series, by inputting Numpy array
PS = pd.Series(TA)
PS
#output
0 32
1 19
2 301
3 7
dtype: int32
We have seen the process of creating Series from inputting array is quite simple. However, we have to note that both the array and Series point to the same object in Python working session. If we change the value of one of them, the other will change automatically too. Next example shows this mechanism.
#change the value of element of array
TA[3] = 13
TA
#output
array([ 32, 19, 301, 13])
PS
#output, corresponding element in Series changed too
0 32
1 19
2 301
3 13
dtype: int32
#change the value of element in Series
PS[3] = 32
PS
#output
0 32
1 19
2 301
3 32
TA
#output, corresponding value of element in array changed too
array([ 32, 19, 301, 32])
Click here to download Python Course Source Files !
For online Python training registration, click here ! Pandas provides flexible ways of generating data…
For online Python training registration, click here ! Data frame is the tabular data object…
Click her for course registration ! When a data frame in Python is created via…
We provide affordable online training course(via ZOOM meeting) for Python and R programming at fundamental…