Data Handling Using Pandas - 1-2-1
Data Handling Using Pandas - 1-2-1
1) Python Imaging Library( PIL): PIL is one Data is stored in different formats- .csv file, Excel
of the core libraries for image manipulation in file or an HTML file. This data is converted into a
Python. single format and stored somewhere. This is
2) Numpy Library: This library provides math called Data Warehousing. After storing the data,
functions, scientific computing etc. analysis is done on this data. Once analysis is
3) Pandas: Pandas provides data manipulation done, we can plot this data in the form of a graph
and analysis. which is Data Visualization. All this sequences of
4) Matplotlib: This library is for data operation for data analysis can be easily and
visualization. effectively performed by Python and its libraries.
import pandas as pd
For Example: Suppose we have a Series object s1 as Program to implement Vector Operation on
0 10 Series object
1 20
2 30 import pandas as pd
3 40 s1=pd.Series(range(1,11,2))
dtype : int64 print(s1)
print(s1*4)
If we give condition as: print(s1>10)
Then output will be:
0 False Output:
1 True 0 1
2 True 1 3
3 True 2 5
dtype: bool 3 7
4 9
When we apply this condition with the Series dtype: int64
object inside [], we will find that it will return 0 4
filtered result containing only. 1 12
For Example: Suppose we have a Series object s1 as 2 20
3 28 0 False
4 36 1 False
dtype: int64 2 False
3 False
Program to implement Arithmetic on Series 4 True
object 5 True
6 True
import pandas as pd dtype: bool
s1=pd.Series(range(1,11,2)) 4 13
s2=pd.Series(range(11,21,2)) 5 16
print(s1+s2) 6 19
dtype: int64
Output:
0 12 Program to implement head() and tail() of a Series
1 16 Object
2 20
3 24 import pandas as pd
4 28 s1=pd.Series(range(1,20,3))
dtype: int64 print(s1.head(3))
print(s1.tail(2))
Program to implement Arithmetic on Series
object with mismatched Index print(s1.head())
print(s1.tail())
import pandas as pd
s1=pd.Series(range(1,11,2)) Output:
s2=pd.Series(range(11,21,2)) 0 1
s2.index=[1,2,3,4,5] 1 4
print(s1+s2) 2 7
dtype: int64
Output: 5 16
0 NaN 6 19
1 14.0 dtype: int64
2 18.0 0 1
3 22.0 1 4
4 26.0 2 7
5 NaN 3 10
dtype: float64 4 13
dtype: int64
Program to implement filtering conditions in a 2 7
Series object 3 10
import pandas as pd 4 13
s1=pd.Series(range(1,20,3)) 5 16
print(s1) 6 19
print(s1>10) dtype: int64
print(s1[s1>10])
Output:
0 1
1 4
2 7
3 10
4 13
5 16
6 19
dtype: int64
Program to sort a Series on the basis of values Program to sort a Series on the basis of index
0 10
1 20
3 30
2 40
5 50
4 60
7 80
6 100
dtype: int64