Page 223 - Ai Book - 10
P. 223
Output:
[[0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0.]]
Example 6: Program to create 2D array of 2 rows and 3 columns with all 5 as value.
import numpy as np
a = np.full((2,3),5)
print(a)
Output:
[[5 5 5]
[5 5 5]]
Pandas
Pandas is a popular Python package for data science because it offers
powerful, expressive and flexible data structures that make data
manipulation and analysis easy, among many other things. The name
Pandas is derived from the word Panel Data – an Econometrics from
Multidimensional data.
It was developed in 2008 when a programmer required a high performance, flexible tool for data analysis.
The Pandas have two main structures i.e.,Series (1-dimensional) and DataFrame (2-dimensional) that handle the
vast majority of typical use cases in finance, statistics, social science, and many areas of engineering. Pandas is
built on top of NumPy and is intended to integrate well within a scientific computing environment with many
other 3rd party libraries.The important features of Pandas are as follows:
u Fast and efficient DataFrame object to manage and explore data.
u Organization and labeling of data are perfectly done by the intelligent methods of alignment and indexing
u Integrated handling of missing data values.
u Optimising performance.
u Columns from a data structure can be deleted or inserted.
u Group by data for aggregation and transformations.
u Easy implementation of Mathematical operation on the datasets.
Now, let us learn how to create a Series, a one-dimensional array which can store data of any type in Jupyter
Notebook. To create a Pandas Series, you should follow the given steps:
u Import the Pandas package with the help of Python’s import command:
import pandas as pd
Here, ‘pd’ is used to call the pandas library.
u You can create the Series by invoking the pd.Series() method. In this method, you can define an array like:
initial_series = pd.Series([10,20,30,40,50])
u Display the content of Series with the help of the Print command such as:
print(initial_series)
Hence, we can create a Pandas series by the following lines of code:
97
97