Page 210 - AI Ver 3.0 Class 11
P. 210
Brainy Fact
Pandas performs better with datasets containing 500,000 rows or more, while NumPy excels with datasets
of 50,000 rows or fewer. When it comes to indexing, Pandas series are significantly slower than NumPy
arrays, which have very fast indexing capabilities.
Program 39: To create a series from a list
import pandas as pd
# Creating a series from a list
data = [1, 2, 3, 4, 5]
series = pd.Series(data)
print(series)
Output:
0 1
1 2
2 3
3 4
4 5
dtype: int64
DataFrames
In pandas, a DataFrame is a two-dimensional labelled data structure, similar to a table in a spreadsheet or a database.
It consists of rows and columns, where each column can have a different data type (like integers, floats, strings, etc.).
Some examples of a DataFrame are: class’s result, menu items in a restaurant, or a train's reservation chart, etc.
Index Name Test 1 Test 2 Test 3
0 Amit 92 75 79
1 Yash 81 85 84
2 Rohan 76 72 85
3 Devesh 78 83 90
4 Nihar 92 87 87
Creating a DataFrame
There are several ways depending on the data source and structure by which you can create a dataframe in Pandas.
Some most common method for creating a DataFrame are:
• • From Lists or Arrays: You can create a DataFrame by passing a list or a NumPy array to the pd.DataFrame()
constructor. Each element of the list or array will be treated as a row.
Program 40: To create a DataFrame using lists or arrays
import pandas as pd
data = [[1, 'Mayur', 25],
208 Touchpad Artificial Intelligence (Ver. 3.0)-XI

