Pandas Library
Pandas Library
Description:
A Series is a one-dimensional labeled array capable of holding any
data type (integers, strings, floating point numbers, Python objects,
etc.). It has to be remembered that unlike Python lists, a Series will
always contain data of the same type. We can craete a panda series
from a dictionary using " series ( ) " method. In this case, dictionary
keys are taken in a sorted order to construct index.
21
Code:
#creating Panda Series from a dictionary
import pandas as pd
dictionary={'Meghana' : 31, 'Asritha' : 5, 'Sreeja' : 59, 'Mahathi' : 36}
series=pd.Series(dictionary)
print(series)
Sample Output:
Meghana 31
Asritha 5
Sreeja 59
Mahathi 36
dtype: int64
Sample Output:
name no. sec
0 meghu 34 CSM
1 sreeja 59 CSM
2 asri 5 CSM
3 mahathi 36 CSM
Description:
describe( ) :-
This function describes different types of statstics like count,mean,
Standard deviation, minimal value, First Quartile, Second Quartile,
Third Quartile and maximum value.
Code:
#For describe function
import pandas as pd
date = [[31, 1, 2], [12, 5, 3], [5, 6, 3]]
df = pd.DataFrame(date)
print(df.describe())
23
Sample Output:
0 1 2
count 3.000000 3.000000 3.000000
mean 16.000000 4.000000 2.666667
std 13.453624 2.645751 0.577350
min 5.000000 1.000000 2.000000
25% 8.500000 3.000000 2.500000
50% 12.000000 5.000000 3.000000
75% 21.500000 5.500000 3.000000
max 31.000000 6.000000 3.000000
Description:
head( ) :- This method gives headers and a specified number of
rows starting from top. By default it returns top most 5 values.
Code:
#For head function
import pandas as pd
date = [[31, 1, 2], [12, 5, 3], [5, 6, 3],[1,3,4],[3,4,5],[67,98,8]]
df = pd.DataFrame(date)
print(df.head(3))
Sample Output:
0 1 2
0 31 1 2
1 12 5 3
2 5 6 3
Description:
tail( ) :- This method gives headers and a specified number of rows
starting from bottom. By default it returns bottom most 5 values.
24
Code:
#For tail function
import pandas as pd
date = [[31, 1, 2], [12, 5, 3], [5, 6, 3],[1,3,4],[3,4,5],[67,98,9,8]]
df = pd.DataFrame(date)
print(df.tail(2))
Sample Output:
0 1 2 3
4 3 4 5 NaN
5 67 98 9 8.0
Description:
info( ) :-This method returns the information like index, column
no., whether it is null or not ,count and datatype.
Code:
#For info function
import pandas as pd
date = [[31, 1, 2], [12, 5, 3], [5, 6, 3],[1,3,4],[3,4,5],[67,98,9,8]]
df = pd.DataFrame(date)
print(df.info())
Sample Output:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 6 entries, 0 to 5
Data columns (total 4 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 0 6 non-null int64
1 1 6 non-null int64
2 2 6 non-null int64
3 3 1 non-null float64
dtypes: float64(1), int64(3)
memory usage: 320.0 bytes
None