[go: up one dir, main page]

0% found this document useful (0 votes)
18 views20 pages

Pandas

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views20 pages

Pandas

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

What is Pandas?

• Python’s pandas library is one of the things that makes Python a great
programming language for data analysis.

• Pandas makes importing, analyzing, and visualizing data much easier.

• It builds on packages like NumPy and matplotlib to give you a single,


convenient, place to do most of your data analysis and visualization
work.
Pandas

Series Dataframe
Series

The Pandas Series can be defined as a one-dimensional array that is


capable of storing various data types. We can easily convert the list,
tuple, and dictionary into series using "series' method.

The row labels of series are called the index. A Series cannot contain
multiple columns.
It has the following parameter:

1. data: It can be any list, dictionary, or scalar value.

2. index: The value of the index should be unique. It must be of the


same length as data. If we do not pass any index,
default np.arrange(n) will be used.

3. dtype: It refers to the data type of series.

4. copy: It is used for copying the data.


In Python, we are used to working with lists as such:

The Series data structure in Pandas is the equivalent of a list in python. It


is a single dimensional data structure, and is represented as a column. A
Python list can be converted into a series in Pandas like so:
When a series is printed, the output is represented in two columns.
The values in the left column is known as the index. If no index is
specified, it is automatically generated and ranges from 0 to n-1,
where n is the number of elements in the Series.

However, it is possible to assign a custom index to a series by passing


the index argument when converting a list to a series.
Take note that the index argument must have the same number of
elements as the list that is being converted to a series.
Creating a Series:

We can create a Series in two ways:

1. Create an empty Series


2. Create a Series using inputs.
Create an Empty Series:

We can easily create an empty series in Pandas which means it will not
have any value.

The syntax that is used for creating an Empty Series:

<series object> = pandas.Series()


The below example creates an Empty Series type object that has no
values and having default datatype, i.e., float64.
Creating a Series using inputs:

We can create Series by using various inputs:

• Array

• Dict

• Scalar value
Creating Series from Array:

• Before creating a Series, firstly, we have to import the numpy module


and then use array() function in the program. If the data is ndarray,
then the passed index must be of the same length.

• If we do not pass an index, then by default index of range(n) is being


passed where n defines the length of an array, i.e.,
[0,1,2,....range(len(array))-1].
Example
Create a Series from dict

• We can also create a Series from dict. If the dictionary object is being
passed as an input and the index is not specified, then the
dictionary keys are taken in a sorted order to construct the index.

• If index is passed, then values correspond to a particular label in the


index will be extracted from the dictionary.
Example
Create a Series using Scalar:

If we take the scalar values, then the index must be provided. The
scalar value will be repeated for matching the length of the index.
Accessing data from series with Position:

• Once you create the Series type object, you can access its indexes,
data, and even individual elements.

• The data in the Series can be accessed similar to that in the ndarray.
Series object attributes
Retrieving Index array and data array of a
series object

We can retrieve the index array and data array of an existing Series
object by using the attributes index and values.

You might also like