KEMBAR78
PPT data science python sequence numpy.pptx
Python for Data Science
Week 2
What we learnt this week ?
 Sequence Data Types
 Strings
 Lists
 Tuple
 Dictionary
 Sets
 Numpy
What are Sequence Data Types ?
 Sequence Data Types allows us to store multiple values in an organized and
efficient fashion.
 String, List, Tuple are some example of Sequential types
 Dictionaries and Sets are container for Non-sequential data.
Strings
 String is an immutable sequence data type.
 Immutable – which can’t be changed
 It is the sequence of Unicode characters wrapped inside single, double, or triple
quotes.
 Example:
 ‘This is a string in Python’
 “This is a ‘string’ in Python”
 ‘“This is a “string” in Python”’
Functions/Methods on String
 string*n - repeats the given string n times
 upper() - Converts a string into upper case
 lower() - Converts a string into lower case
 split() - Splits the string at the specified separator, and returns a list
 index() - Searches the string for a specified value and returns the position of where it is
found
 count() - Returns the number of times a specified value occurs in a string
 capitalize() – Returns the string with its first character capitalized and the rest lowercased
Lists
 A list is an ordered and mutable Python container.
 Lists are used to store multiple items in a single variable.
 Lists are created using square brackets
 Example:
 myList = [1 , 2 , 3 , 4 , 5]
 myList = [1 , ‘two’ , 3 , ‘four’ , 5]
 myList = [1 , [‘a’ , ‘b’ , ‘c’] , ‘hello’]
Functions/Methods on Lists
 append() - Adds an element at the end of the list
 pop() - Removes the element at the specified position
 clear() - Removes all the elements from the list
 insert() - Adds an element at the specified position
 reverse() - Reverses the order of the list
 extend() - Add the elements of a list (or any iterable), to the end of the current list
Dictionary
 Used to store data values in key:value pairs.
 Dictionaries are written with curly brackets, and have keys and values
 Syntax:-
{'key1':'value1','key2':'value2'}
 Duplicates not Allowed
Dictionaries cannot have two items with the same key.
 Example
mydictionary = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
Numpy and Numpy Array
 Numpy is a Python package and it stands for numerical python.
 A numpy array is a grid of values, all of the same type.
 To install numpy on your system, run this command on your CMD
pip install numpy
 To create numpy array, we first need to import the numpy package:
import numpy as np
 Example:-
array = np.array([1,2,3,4,5], dtype = int )
Methods/Functions
 type(array) – this will give you the Datatype of Array
 len(array) – length of array
 array.ndim - return the number of dimensions of an array
 array.shape - returns a tuple with each index having the number of
corresponding elements
 array.reshape – it changes the shape of the array
Thank You
For your Patience

PPT data science python sequence numpy.pptx

  • 1.
    Python for DataScience Week 2
  • 2.
    What we learntthis week ?  Sequence Data Types  Strings  Lists  Tuple  Dictionary  Sets  Numpy
  • 3.
    What are SequenceData Types ?  Sequence Data Types allows us to store multiple values in an organized and efficient fashion.  String, List, Tuple are some example of Sequential types  Dictionaries and Sets are container for Non-sequential data.
  • 4.
    Strings  String isan immutable sequence data type.  Immutable – which can’t be changed  It is the sequence of Unicode characters wrapped inside single, double, or triple quotes.  Example:  ‘This is a string in Python’  “This is a ‘string’ in Python”  ‘“This is a “string” in Python”’
  • 5.
    Functions/Methods on String string*n - repeats the given string n times  upper() - Converts a string into upper case  lower() - Converts a string into lower case  split() - Splits the string at the specified separator, and returns a list  index() - Searches the string for a specified value and returns the position of where it is found  count() - Returns the number of times a specified value occurs in a string  capitalize() – Returns the string with its first character capitalized and the rest lowercased
  • 6.
    Lists  A listis an ordered and mutable Python container.  Lists are used to store multiple items in a single variable.  Lists are created using square brackets  Example:  myList = [1 , 2 , 3 , 4 , 5]  myList = [1 , ‘two’ , 3 , ‘four’ , 5]  myList = [1 , [‘a’ , ‘b’ , ‘c’] , ‘hello’]
  • 7.
    Functions/Methods on Lists append() - Adds an element at the end of the list  pop() - Removes the element at the specified position  clear() - Removes all the elements from the list  insert() - Adds an element at the specified position  reverse() - Reverses the order of the list  extend() - Add the elements of a list (or any iterable), to the end of the current list
  • 8.
    Dictionary  Used tostore data values in key:value pairs.  Dictionaries are written with curly brackets, and have keys and values  Syntax:- {'key1':'value1','key2':'value2'}  Duplicates not Allowed Dictionaries cannot have two items with the same key.  Example mydictionary = { "brand": "Ford", "model": "Mustang", "year": 1964 }
  • 9.
    Numpy and NumpyArray  Numpy is a Python package and it stands for numerical python.  A numpy array is a grid of values, all of the same type.  To install numpy on your system, run this command on your CMD pip install numpy  To create numpy array, we first need to import the numpy package: import numpy as np  Example:- array = np.array([1,2,3,4,5], dtype = int )
  • 10.
    Methods/Functions  type(array) –this will give you the Datatype of Array  len(array) – length of array  array.ndim - return the number of dimensions of an array  array.shape - returns a tuple with each index having the number of corresponding elements  array.reshape – it changes the shape of the array
  • 11.