Page 193 - Robotics and AI class 10
P. 193
Data Structures in Pandas
Two commonly used data structures in Pandas are:
● Series
● DataFrames
Series
Series is a one-dimensional array that can store data of any type like integer, string, float, python objects, etc. We
can also say that the Pandas series is just like a column of a spreadsheet.
The values can be referred to by using data axis labels also called index. Indexes are of two types: positional index
and labelled index. Positional indexes are integers starting with default 0 whereas labelled indexes are user defined
labels that can be of any datatype and can be used as an index.
Pandas Series can be created by loading the datasets from existing storage like SQL Database, CSV file, and Excel
file. Pandas Series can also be created from the lists, dictionary, and from any other scalar value.
Different ways of creating Series are:
• Creating an empty series
import pandas as pd
Emp=pd.Series()
• Creating a Series from a NumPy array
import pandas as pd
import numpy as np
data = np.array([10, 30, 50])
s1 = pd.Series(data)
print(s1)
Output:
0 10
1 30
2 50
dtype: int64
• Creating series using labelled index
import pandas as pd
friends = pd.Series(["Rohan", "Susan", "James"], index=[11,22,33])
print(friends)
Output:
11 Rohan
22 Susan
33 James
dtype: object
• Creating a Series from a Python list
import pandas as pd
cities = ['Delhi', 'Mumbai', 'Chennai', 'Kolkata']
s2 = pd.Series(cities)
print(s2)
Introduction to Data and Programming with Python 191

