In [1]:
Agenda = '''
1. Built in Exception
2. User Define Exception
3. Data Science Introduction
4. Numpy
    a) Array 
    b) Matrix
5. pandas 
    a) Series
    b) Dataframe
6. Matplotlib
    a) Visualisation of Data
7. Data Science Case Study 
8. Summary and Conclusion
'''

Exception in Python

In [2]:
data = int(input("Enter Some data:"))
Enter Some data:hi
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-42575b99cd48> in <module>
----> 1 data = int(input("Enter Some data:"))

ValueError: invalid literal for int() with base 10: 'hi'
In [3]:
data = int(input("Enter Some data:"))
Enter Some data:34
In [4]:
hi
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-4-55ca6286e3e4> in <module>
----> 1 hi

NameError: name 'hi' is not defined
In [5]:
dir(Exception)
Out[5]:
['__cause__',
 '__class__',
 '__context__',
 '__delattr__',
 '__dict__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattribute__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__lt__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__setstate__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__suppress_context__',
 '__traceback__',
 'args',
 'with_traceback']
In [6]:
help(Exception)
Help on class Exception in module builtins:

class Exception(BaseException)
 |  Common base class for all non-exit exceptions.
 |  
 |  Method resolution order:
 |      Exception
 |      BaseException
 |      object
 |  
 |  Methods defined here:
 |  
 |  __init__(self, /, *args, **kwargs)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  ----------------------------------------------------------------------
 |  Static methods defined here:
 |  
 |  __new__(*args, **kwargs) from builtins.type
 |      Create and return a new object.  See help(type) for accurate signature.
 |  
 |  ----------------------------------------------------------------------
 |  Methods inherited from BaseException:
 |  
 |  __delattr__(self, name, /)
 |      Implement delattr(self, name).
 |  
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |  
 |  __reduce__(...)
 |      Helper for pickle.
 |  
 |  __repr__(self, /)
 |      Return repr(self).
 |  
 |  __setattr__(self, name, value, /)
 |      Implement setattr(self, name, value).
 |  
 |  __setstate__(...)
 |  
 |  __str__(self, /)
 |      Return str(self).
 |  
 |  with_traceback(...)
 |      Exception.with_traceback(tb) --
 |      set self.__traceback__ to tb and return self.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from BaseException:
 |  
 |  __cause__
 |      exception cause
 |  
 |  __context__
 |      exception context
 |  
 |  __dict__
 |  
 |  __suppress_context__
 |  
 |  __traceback__
 |  
 |  args

In [8]:
help(BaseException)
Help on class BaseException in module builtins:

class BaseException(object)
 |  Common base class for all exceptions
 |  
 |  Methods defined here:
 |  
 |  __delattr__(self, name, /)
 |      Implement delattr(self, name).
 |  
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |  
 |  __init__(self, /, *args, **kwargs)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  __reduce__(...)
 |      Helper for pickle.
 |  
 |  __repr__(self, /)
 |      Return repr(self).
 |  
 |  __setattr__(self, name, value, /)
 |      Implement setattr(self, name, value).
 |  
 |  __setstate__(...)
 |  
 |  __str__(self, /)
 |      Return str(self).
 |  
 |  with_traceback(...)
 |      Exception.with_traceback(tb) --
 |      set self.__traceback__ to tb and return self.
 |  
 |  ----------------------------------------------------------------------
 |  Static methods defined here:
 |  
 |  __new__(*args, **kwargs) from builtins.type
 |      Create and return a new object.  See help(type) for accurate signature.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __cause__
 |      exception cause
 |  
 |  __context__
 |      exception context
 |  
 |  __dict__
 |  
 |  __suppress_context__
 |  
 |  __traceback__
 |  
 |  args

Handle Exception

In [9]:
try:
    data = int(input("Enter Some data:"))
except ValueError as e:
    print("Enter Integer Value only::",e )
else:
    print("Your data is", data)
    
Enter Some data:hi
Enter Integer Value only:: invalid literal for int() with base 10: 'hi'
In [10]:
while True:
    try:
        data = int(input("Enter Some data:"))
    except ValueError as e:
        print("Enter Integer Value only::",e )
    else:
        print("Your data is", data)
        break
        
    
Enter Some data:hi
Enter Integer Value only:: invalid literal for int() with base 10: 'hi'
Enter Some data:343
Your data is 343

User Define Exception

In [18]:
%%writefile ShortInputModule.py

'''User Define Exception Module. 
ShortInput Exception. It should raise ShortInput Exception 
for the data of length less than six bytes ( chars ).
'''

class ShortInput(Exception):  # Subclass of Exception Class
    
    ''' ShortInput Exception. It should raise ShortInput Exception 
for the data of length less than six bytes ( chars ).'''
    
    def __init__(self, inputdata, atleast):
        '''Initialise ShortInput Class with data and minimum size'''
        self.inputdata = inputdata
        self.atleast = atleast
        
        print("Your input data size is %d bytes which is shorter than \
expected data %d bytes"%(inputdata, atleast))


if __name__ == '__main__':
    Ob1 = ShortInput(5, 6)
Overwriting ShortInputModule.py
In [19]:
from ShortInputModule import ShortInput

help(ShortInput)
Help on class ShortInput in module ShortInputModule:

class ShortInput(builtins.Exception)
 |  ShortInput(inputdata, atleast)
 |  
 |  ShortInput Exception. It should raise ShortInput Exception 
 |  for the data of length less than six bytes ( chars ).
 |  
 |  Method resolution order:
 |      ShortInput
 |      builtins.Exception
 |      builtins.BaseException
 |      builtins.object
 |  
 |  Methods defined here:
 |  
 |  __init__(self, inputdata, atleast)
 |      Initialise ShortInput Class with data and minimum size
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)
 |  
 |  ----------------------------------------------------------------------
 |  Static methods inherited from builtins.Exception:
 |  
 |  __new__(*args, **kwargs) from builtins.type
 |      Create and return a new object.  See help(type) for accurate signature.
 |  
 |  ----------------------------------------------------------------------
 |  Methods inherited from builtins.BaseException:
 |  
 |  __delattr__(self, name, /)
 |      Implement delattr(self, name).
 |  
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |  
 |  __reduce__(...)
 |      Helper for pickle.
 |  
 |  __repr__(self, /)
 |      Return repr(self).
 |  
 |  __setattr__(self, name, value, /)
 |      Implement setattr(self, name, value).
 |  
 |  __setstate__(...)
 |  
 |  __str__(self, /)
 |      Return str(self).
 |  
 |  with_traceback(...)
 |      Exception.with_traceback(tb) --
 |      set self.__traceback__ to tb and return self.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from builtins.BaseException:
 |  
 |  __cause__
 |      exception cause
 |  
 |  __context__
 |      exception context
 |  
 |  __dict__
 |  
 |  __suppress_context__
 |  
 |  __traceback__
 |  
 |  args

In [20]:
import ShortInputModule

help(ShortInputModule)
Help on module ShortInputModule:

NAME
    ShortInputModule

DESCRIPTION
    User Define Exception Module. 
    ShortInput Exception. It should raise ShortInput Exception 
    for the data of length less than six bytes ( chars ).

CLASSES
    builtins.Exception(builtins.BaseException)
        ShortInput
    
    class ShortInput(builtins.Exception)
     |  ShortInput(inputdata, atleast)
     |  
     |  ShortInput Exception. It should raise ShortInput Exception 
     |  for the data of length less than six bytes ( chars ).
     |  
     |  Method resolution order:
     |      ShortInput
     |      builtins.Exception
     |      builtins.BaseException
     |      builtins.object
     |  
     |  Methods defined here:
     |  
     |  __init__(self, inputdata, atleast)
     |      Initialise ShortInput Class with data and minimum size
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  ----------------------------------------------------------------------
     |  Static methods inherited from builtins.Exception:
     |  
     |  __new__(*args, **kwargs) from builtins.type
     |      Create and return a new object.  See help(type) for accurate signature.
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.BaseException:
     |  
     |  __delattr__(self, name, /)
     |      Implement delattr(self, name).
     |  
     |  __getattribute__(self, name, /)
     |      Return getattr(self, name).
     |  
     |  __reduce__(...)
     |      Helper for pickle.
     |  
     |  __repr__(self, /)
     |      Return repr(self).
     |  
     |  __setattr__(self, name, value, /)
     |      Implement setattr(self, name, value).
     |  
     |  __setstate__(...)
     |  
     |  __str__(self, /)
     |      Return str(self).
     |  
     |  with_traceback(...)
     |      Exception.with_traceback(tb) --
     |      set self.__traceback__ to tb and return self.
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from builtins.BaseException:
     |  
     |  __cause__
     |      exception cause
     |  
     |  __context__
     |      exception context
     |  
     |  __dict__
     |  
     |  __suppress_context__
     |  
     |  __traceback__
     |  
     |  args

DATA
    Ob1 = ShortInput(5, 6)

FILE
    /Users/surendra/ShortInputModule.py


In [22]:
from ShortInputModule import ShortInput


while True:
    try:
        data = input("Enter Some data:")
        if len(data) < 6:
            raise ShortInput(len(data), 6)
    except ShortInput as e:
        print("Shortinput Exception Occurred",e )
    else:
        print("Your data is", data)
        break
Enter Some data:3434
Your input data size is 4 bytes which is shorter than expected data 6 bytes
Shortinput Exception Occurred (4, 6)
Enter Some data:242329389
Your data is 242329389

Numpy

Numpy is multidimensional array and matrices ( 2 dimension ) librarary.

List Addition

In [24]:
import numpy as np

List1 = list(range(1,10))

print(List1)

List2 = list(range(11,20))

print(List2)

List3 = List1 + List2

print(List3)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[11, 12, 13, 14, 15, 16, 17, 18, 19]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19]

Array Addition

In [27]:
Array1 = np.array(List1)
print(Array1)



Array2 = np.array(List2)
print(Array2)



Array3 = Array1 + Array2

print(Array3)
[1 2 3 4 5 6 7 8 9]
[11 12 13 14 15 16 17 18 19]
[12 14 16 18 20 22 24 26 28]

Array Dimension

In [28]:
print(Array1.ndim)
1

Array Shape

In [29]:
print(Array1.shape)
(9,)

Array Item Size

In [30]:
print(Array1.itemsize)
8

Array Data Type

In [32]:
Array1.dtype
Out[32]:
dtype('int64')

Array Reshape

In [40]:
print("\n Create Array of 15 items \n")

Array4 = np.arange(1,16)

print(Array4)

print("Dimension of Array: ", Array4.ndim)

print("Shape of the Array")

print(Array4.shape)

print("\n Reshape Array")

Array5 = Array4.reshape(3,5)

print(Array5)

print("\n Modified Shape of the Array \n")

print(Array5.shape)

print("\n New Dimension of Array is ",Array5.ndim)
 Create Array of 15 items 

[ 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15]
Dimension of Array:  1
Shape of the Array
(15,)

 Reshape Array
[[ 1  2  3  4  5]
 [ 6  7  8  9 10]
 [11 12 13 14 15]]

 Modified Shape of the Array 

(3, 5)

 New Dimension of Array is  2

Trasponse of Array

In [41]:
Array5
Out[41]:
array([[ 1,  2,  3,  4,  5],
       [ 6,  7,  8,  9, 10],
       [11, 12, 13, 14, 15]])
In [42]:
Array6 = Array5.T
Array6
Out[42]:
array([[ 1,  6, 11],
       [ 2,  7, 12],
       [ 3,  8, 13],
       [ 4,  9, 14],
       [ 5, 10, 15]])

Subscripting of Array

In [43]:
# First row of array5 

Array5[0]
Out[43]:
array([1, 2, 3, 4, 5])
In [47]:
# First column of array5 

Array5[:,0]
Out[47]:
array([ 1,  6, 11])
In [52]:
# Second row and second column of array5 

Array5[1:2,1:2]
Out[52]:
array([[7]])
In [56]:
# Second Row and third and Fourth column 

print(Array5[1:, 2:4])
[[ 8  9]
 [13 14]]
In [61]:
# Alternate Rows and Alaternate Columns

print("\n Alternate Rows \n ")

print(Array5[::2, :])

print("\nAlternate Columns \n")

print(Array5[:, ::2])
 Alternate Rows 
 
[[ 1  2  3  4  5]
 [11 12 13 14 15]]

Alternate Columns 

[[ 1  3  5]
 [ 6  8 10]
 [11 13 15]]
In [63]:
#dir(Array5)
In [66]:
Array5.sum()
Out[66]:
120
In [67]:
Array5.max()
Out[67]:
15
In [68]:
Array5.min()
Out[68]:
1
In [69]:
Array5.mean()
Out[69]:
8.0
In [70]:
Array5.std()
Out[70]:
4.320493798938574
In [75]:
print("Change Array Type to float32 ")

Array7 = Array5.astype('float32')
print(Array7)

print("\n Array Data Type :")
print(Array7.dtype)
Change Array Type to float32 
[[ 1.  2.  3.  4.  5.]
 [ 6.  7.  8.  9. 10.]
 [11. 12. 13. 14. 15.]]

 Array Data Type :
float32

Matrix using Array

Matrix is a two dimensional array. 
In [76]:
Mat1 = np.matrix(Array1)

print(Mat1)

print(Mat1.ndim)
[[1 2 3 4 5 6 7 8 9]]
2
In [77]:
Mat2 = np.matrix(Array5)

print(Mat2)

print(Mat2.ndim)
[[ 1  2  3  4  5]
 [ 6  7  8  9 10]
 [11 12 13 14 15]]
2
In [79]:
# Transpose of Matrix 

Mat3 = Mat2.T
print(Mat3)
[[ 1  6 11]
 [ 2  7 12]
 [ 3  8 13]
 [ 4  9 14]
 [ 5 10 15]]
In [80]:
# Inverse of Matrix 

Mat5 = Mat2.I
print(Mat5)
[[-2.46666667e-01 -6.66666667e-02  1.13333333e-01]
 [-1.33333333e-01 -3.33333333e-02  6.66666667e-02]
 [-2.00000000e-02 -2.51534904e-17  2.00000000e-02]
 [ 9.33333333e-02  3.33333333e-02 -2.66666667e-02]
 [ 2.06666667e-01  6.66666667e-02 -7.33333333e-02]]

Pandas

1. Pandas is a software library written for the Python programming language for data manipulation and analysis.
2. DataFrame object for data manipulation with integrated indexing.
3.Tools for reading and writing data between in-memory data structures and different file formats.
4.Data alignment and integrated handling of missing data.
5. Reshaping and pivoting of data sets.
6.Label-based slicing, fancy indexing, and subsetting of large data sets.
7. Data structure column insertion and deletion.
8. Group by engine allowing split-apply-combine operations on data sets.
9. Data set merging and joining.
10. Hierarchical axis indexing to work with high-dimensional data in a lower-dimensional data structure.
11. Time series-functionality: Date range generation and frequency conversion, moving window statistics, moving window linear regressions, date shifting and lagging.
12. Provides data filtration.
In [85]:
import pandas as pd

EmpName = ["Amit", "Amar", "Akabar", "Anthony", "Isha", "Disha", "Hema"]

Salary = [200000, 300000, 400000, 500000, 250000, 350000, 100000] 

print("\n Employee Name Series \n")

Series1 = pd.Series(EmpName)

print(Series1)

print("\n Employee Salary Series \n ")

Series2 = pd.Series(Salary)

print(Series2)
 Employee Name Series 

0       Amit
1       Amar
2     Akabar
3    Anthony
4       Isha
5      Disha
6       Hema
dtype: object

 Employee Salary Series 
 
0    200000
1    300000
2    400000
3    500000
4    250000
5    350000
6    100000
dtype: int64
In [88]:
#dir(pd.Series)
In [89]:
EmpDict = dict(zip(EmpName, Salary))
print(EmpDict)
{'Amit': 200000, 'Amar': 300000, 'Akabar': 400000, 'Anthony': 500000, 'Isha': 250000, 'Disha': 350000, 'Hema': 100000}
In [90]:
EmpSeries = pd.Series(EmpDict)

print(EmpSeries)
Amit       200000
Amar       300000
Akabar     400000
Anthony    500000
Isha       250000
Disha      350000
Hema       100000
dtype: int64
In [91]:
EmpSeries.index
Out[91]:
Index(['Amit', 'Amar', 'Akabar', 'Anthony', 'Isha', 'Disha', 'Hema'], dtype='object')
In [92]:
EmpSeries.values
Out[92]:
array([200000, 300000, 400000, 500000, 250000, 350000, 100000])
In [93]:
EmpSeries.keys()
Out[93]:
Index(['Amit', 'Amar', 'Akabar', 'Anthony', 'Isha', 'Disha', 'Hema'], dtype='object')
In [96]:
EmpSeries.value_counts()
Out[96]:
300000    1
100000    1
350000    1
500000    1
250000    1
400000    1
200000    1
dtype: int64
In [98]:
EmpSeries['Amit']
Out[98]:
200000
In [99]:
EmpSeries['Amit'] = 300000

EmpSeries
Out[99]:
Amit       300000
Amar       300000
Akabar     400000
Anthony    500000
Isha       250000
Disha      350000
Hema       100000
dtype: int64
In [100]:
EmpSeries.ndim
Out[100]:
1
In [101]:
EmpSeries.shape
Out[101]:
(7,)
In [103]:
EmpSeries.max()
Out[103]:
500000
In [104]:
EmpSeries.mean()
Out[104]:
314285.71428571426
In [105]:
EmpSeries.min()
Out[105]:
100000
In [106]:
EmpSeries.sum()
Out[106]:
2200000
In [107]:
EmpSeries.dtype
Out[107]:
dtype('int64')
In [108]:
EmpSeries.dtypes
Out[108]:
dtype('int64')
In [109]:
EmpSeries[:3]
Out[109]:
Amit      300000
Amar      300000
Akabar    400000
dtype: int64
In [111]:
EmpSeries[2:]
Out[111]:
Akabar     400000
Anthony    500000
Isha       250000
Disha      350000
Hema       100000
dtype: int64

Pandas DataFrame

In [117]:
df = pd.DataFrame(EmpSeries)
In [120]:
df.columns
Out[120]:
RangeIndex(start=0, stop=1, step=1)
In [121]:
df.index
Out[121]:
Index(['Amit', 'Amar', 'Akabar', 'Anthony', 'Isha', 'Disha', 'Hema'], dtype='object')
In [125]:
df.ndim
Out[125]:
2
In [126]:
df.dtypes
Out[126]:
0    int64
dtype: object
In [127]:
df.shape
Out[127]:
(7, 1)
In [131]:
df.columns=['Salary']
In [132]:
df
Out[132]:
Salary
Amit 300000
Amar 300000
Akabar 400000
Anthony 500000
Isha 250000
Disha 350000
Hema 100000
In [133]:
df['Salary']
Out[133]:
Amit       300000
Amar       300000
Akabar     400000
Anthony    500000
Isha       250000
Disha      350000
Hema       100000
Name: Salary, dtype: int64
In [135]:
df['Salary'].max()
Out[135]:
500000
In [136]:
df['Salary'].mean()
Out[136]:
314285.71428571426
In [137]:
df['Salary'].sum()
Out[137]:
2200000
In [139]:
df.describe()
Out[139]:
Salary
count 7.000000
mean 314285.714286
std 124880.895638
min 100000.000000
25% 275000.000000
50% 300000.000000
75% 375000.000000
max 500000.000000
In [140]:
df.Salary
Out[140]:
Amit       300000
Amar       300000
Akabar     400000
Anthony    500000
Isha       250000
Disha      350000
Hema       100000
Name: Salary, dtype: int64
In [141]:
df.Salary.plot()
Out[141]:
<matplotlib.axes._subplots.AxesSubplot at 0x126eefa50>
In [143]:
df.info()
<class 'pandas.core.frame.DataFrame'>
Index: 7 entries, Amit to Hema
Data columns (total 1 columns):
Salary    7 non-null int64
dtypes: int64(1)
memory usage: 432.0+ bytes
In [144]:
df1 = pd.DataFrame(zip(EmpName,Salary))
print(df1)
         0       1
0     Amit  200000
1     Amar  300000
2   Akabar  400000
3  Anthony  500000
4     Isha  250000
5    Disha  350000
6     Hema  100000
In [145]:
df1.columns
Out[145]:
RangeIndex(start=0, stop=2, step=1)
In [146]:
df1.columns = ['EmpName', 'EmpSalary']
In [147]:
df1
Out[147]:
EmpName EmpSalary
0 Amit 200000
1 Amar 300000
2 Akabar 400000
3 Anthony 500000
4 Isha 250000
5 Disha 350000
6 Hema 100000
In [148]:
df1.shape
Out[148]:
(7, 2)
In [149]:
df1.index
Out[149]:
RangeIndex(start=0, stop=7, step=1)
In [151]:
df1.describe()
Out[151]:
EmpSalary
count 7.000000
mean 300000.000000
std 132287.565553
min 100000.000000
25% 225000.000000
50% 300000.000000
75% 375000.000000
max 500000.000000
In [153]:
df1.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 7 entries, 0 to 6
Data columns (total 2 columns):
EmpName      7 non-null object
EmpSalary    7 non-null int64
dtypes: int64(1), object(1)
memory usage: 240.0+ bytes
In [157]:
df1.to_csv('EmpData.csv',index=False)
In [158]:
cat Empdata.csv
EmpName,EmpSalary
Amit,200000
Amar,300000
Akabar,400000
Anthony,500000
Isha,250000
Disha,350000
Hema,100000
In [159]:
pwd
Out[159]:
'/Users/surendra'
In [160]:
path = r'/Users/surendra/Empdata.csv'

df2 = pd.read_csv(path)
df2
Out[160]:
EmpName EmpSalary
0 Amit 200000
1 Amar 300000
2 Akabar 400000
3 Anthony 500000
4 Isha 250000
5 Disha 350000
6 Hema 100000
In [161]:
df2['EmpName']
Out[161]:
0       Amit
1       Amar
2     Akabar
3    Anthony
4       Isha
5      Disha
6       Hema
Name: EmpName, dtype: object
In [162]:
df2['EmpSalary']
Out[162]:
0    200000
1    300000
2    400000
3    500000
4    250000
5    350000
6    100000
Name: EmpSalary, dtype: int64
In [163]:
df2.iloc[:3]
Out[163]:
EmpName EmpSalary
0 Amit 200000
1 Amar 300000
2 Akabar 400000
In [164]:
df2.iloc[0:5]
Out[164]:
EmpName EmpSalary
0 Amit 200000
1 Amar 300000
2 Akabar 400000
3 Anthony 500000
4 Isha 250000
In [165]:
df2[:2]
Out[165]:
EmpName EmpSalary
0 Amit 200000
1 Amar 300000
In [166]:
df2.EmpName
Out[166]:
0       Amit
1       Amar
2     Akabar
3    Anthony
4       Isha
5      Disha
6       Hema
Name: EmpName, dtype: object
In [167]:
df2.head()
Out[167]:
EmpName EmpSalary
0 Amit 200000
1 Amar 300000
2 Akabar 400000
3 Anthony 500000
4 Isha 250000
In [168]:
df2.tail()
Out[168]:
EmpName EmpSalary
2 Akabar 400000
3 Anthony 500000
4 Isha 250000
5 Disha 350000
6 Hema 100000
In [172]:
df2.sort_values('EmpSalary')
Out[172]:
EmpName EmpSalary
6 Hema 100000
0 Amit 200000
4 Isha 250000
1 Amar 300000
5 Disha 350000
2 Akabar 400000
3 Anthony 500000
In [175]:
df2.sort_values('EmpName', ascending = False )
Out[175]:
EmpName EmpSalary
4 Isha 250000
6 Hema 100000
5 Disha 350000
3 Anthony 500000
0 Amit 200000
1 Amar 300000
2 Akabar 400000
In [177]:
df2.plot(kind = 'bar')
Out[177]:
<matplotlib.axes._subplots.AxesSubplot at 0x12b86bed0>
In [179]:
df2.plot(kind = 'line')
Out[179]:
<matplotlib.axes._subplots.AxesSubplot at 0x12b691510>
In [180]:
df2.plot.hist()
Out[180]:
<matplotlib.axes._subplots.AxesSubplot at 0x12b5f0750>
In [186]:
df2.plot(kind = 'barh')
Out[186]:
<matplotlib.axes._subplots.AxesSubplot at 0x12b748ed0>
In [213]:
df2.plot(kind = 'pie',x='EmpName',y='EmpSalary', figsize = (7,5),use_index = True)
Out[213]:
<matplotlib.axes._subplots.AxesSubplot at 0x12d253e90>
In [211]:
df2.plot(kind = 'area',x='EmpName',y='EmpSalary', use_index=True, figsize = (8,8))
Out[211]:
<matplotlib.axes._subplots.AxesSubplot at 0x12cf4bd90>
In [203]:
df2.plot(kind = 'hist',x='EmpName',y='EmpSalary', figsize = (8,5))
Out[203]:
<matplotlib.axes._subplots.AxesSubplot at 0x12c958510>
In [197]:
df2.plot(kind = 'box',x='EmpName',y='EmpSalary', figsize = (8,8))
Out[197]:
<matplotlib.axes._subplots.AxesSubplot at 0x12bd8a050>
In [208]:
 
In [ ]: