Ch 1 Python Pandas-I
Ch 1 Python Pandas-I
Pandas-I
8460831302 Page 1
Python Pandas-I
ch:-1python pandas-i
Advantages of Pandas:-
It can read or write in many different data formats (integer, float, double,
etc.).
It can calculate in all the possible ways data is organized ie across rows and
down columns.
It can easily select subsets of data from bulky data sets and even combine
multiple datasets together. It has functionality to find and fill missing data.
It allows you to apply operations to independent groups within the data.
8460831302 Page 2
Python Pandas-I
1.2 series
Series is Pandas data structure that represents a one dimensional array like
object containing an array of data (of any NumPy data type) and an
8460831302 Page 3
Python Pandas-I
print(s)
output:-
0 0
1 1
2 2
3 3
4 4
print(s)
output:-
Jan 31
Feb 28
March 31
3 3
8460831302 Page 8
Python Pandas-I
shape (5,)
ndim 1
size 5
hasnans False
empty False
Methods of series:-
8460831302 Page 9
Python Pandas-I
Head()
head() function is used to display starting elements of series.
You can specify no of elements as argument of head function.
If you don’t specify the argument, by default it will display first 5
elements.
Syntax:-Seriesobject.head(n)
E.g:-s.head(3)
Output:-
0 50
1 52
2 54
Tail()
tail() function is used to display ending elements of series.
You can specify no of elements as argument of tail function.
If you don’t specify the argument,by default it will display last 5
elements.
Syntax:-Seriesobject.tail(n)
E.g:-s.tail(3)
Output:-
2 54
3 56
4 58
Count():-
Returns the number of non-NaN values in the Series
Syntax:-Seriesobject.count()
E.g:-s.count()
Output:-
5
8460831302 Page 10
Python Pandas-I
Output:-
Sci 50
Com 52
Arts 54
Before performing arithmetic operation make sure both the series
have same indexes, if it is not same it will display NaN(Not a
Number).
E.g:-
import pandas as pd
c11=pd.Series(data=[25,26,27],index=["Sci","Com","Arts"])
c12=pd.Series(data=[25,26,27],index=["Sci","Com","Arts"])
tot=c11+c12
print(tot)
Output:-
Arts 54.0
Com 52.0
8460831302 Page 11
Python Pandas-I
Hummanities NaN
Sci NaN
Series.sort_values([ =True[False])
E.g:-
s.sort_values()
8460831302 Page 13