Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

WEEKLY REPORT OF DATA ANALYSIS USING PYTHON

Name of the Student and Roll No. Nandini Singh / 220617005


Name of the Company Samatrix.io
Period of the Report Week 1st / 2nd / 3rd / 4th / 2nd
5th / 6th / 7th / 8th / 9th / 10th
Activities undertaken during the week Details of the activity:
Dictionary
List compression, Lambda Function, Map function
in python etc.
Details of field trips under taken (if any) and As it is an Virtual Internship, so in this no such field
summary of results of such trips trips are taken yet.
Learning Points acquired from above activities We got to learn about many activities done in this
week like:-
 A dictionary consists of a collection of key-value
pairs. Each key-value pair maps the key to its
associated value.
 We can define a dictionary by enclosing a
comma-separated list of key-value pairs in
curly braces ({}). A colon (:) separates each
key from its associated value.
 We can also construct a dictionary with the
built-in dict() function. The argument
to dict() should be a sequence of key-value
pairs.
 If the key values are simple strings, they
can be specified as keyword arguments.

If we want to update an entry, we can just assign a


new value to an existing key:

>>>
>>> MLB_team['Seattle'] = 'Seahawks'
>>> MLB_team
{'Colorado': 'Rockies', 'Boston': 'Red Sox', 'Minnesota':
'Twins',
'Milwaukee': 'Brewers', 'Seattle': 'Seahawks', 'Kansas
City': 'Royals'}
To delete an entry, use the del statement,
specifying the key to delete:

>>>
>>> del MLB_team['Seattle']
>>> MLB_team
{'Colorado': 'Rockies', 'Boston': 'Red Sox', 'Minnesota':
'Twins',
'Milwaukee': 'Brewers', 'Kansas City': 'Royals'}
 there are a couple restrictions that
dictionary keys must abide by.

First, a given key can appear in a dictionary only


once. Duplicate keys are not allowed. A dictionary
maps each key to a corresponding value, so it
doesn’t make sense to map a particular key more
than once.

Secondly, a dictionary key must be of a type that is


immutable. We have already seen examples where
several of the immutable types you are familiar
with—integer, float, string, and Boolean—have
served as dictionary keys.

A tuple can also be a dictionary key, because tuples


are immutable:

 By contrast, there are no restrictions on


dictionary values. Literally none at all. A
dictionary value can be any type of object
Python supports, including mutable types
like lists and dictionaries, and user-defined
objects.
 We can use the in operator together with
short-circuit evaluation to avoid raising an
error when trying to access a key that is not
in the dictionary.

The Python dictionary .get() method provides a
convenient way of getting the value of a key from a
dictionary without checking ahead of time whether
the key exists, and without raising an error.

d.get(<key>) searches dictionary d for <key> and


returns the associated value if it is found. If <key> is
not found, it returns None
 If <key> is not found and the
optional <default> argument is specified,
that value is returned instead of None.

d.pop(<key>[, <default>])

Removes a key from a dictionary, if it is present,


and returns its value.

If <key> is present
in d, d.pop(<key>) removes <key> and returns its
assoc d.popitem()

Removes a key-value pair from a dictionary.


d.popitem() removes the last key-value pair added
from d and returns it as a tuple.

 If d is empty, d.popitem() raises


a KeyError exception.

d.update(<obj>)

Merges a dictionary with another dictionary or with


an iterable of key-value pairs.
If <obj> is a dictionary, d.update(<obj>) merges the
entries from <obj> into d. For each key in <obj>:

 If the key is not present in d, the key-value


pair from <obj> is added to d.
 If the key is already present in d, the
corresponding value in d for that key is
updated to the value from <obj>
 We got to know about the different types
of functions used in Dictionary.
 We got to know all about it in a depth.
 List Comprehension:

List comprehension offers a shorter syntax when


we want to create a new list based on the values
of an existing list.

Example
fruits =
["apple", "banana", "cherry", "kiwi", "mango"]
newlist = []
for x in fruits:
if "a" in x:
newlist.append(x)

print(newlist)

Example
fruits =
["apple", "banana", "cherry", "kiwi", "mango"]

newlist = [x for x in fruits if "a" in x]

print(newlist)
 Advantages of List Comprehension
 More time-efficient and space-efficient
than loops.
 Require fewer lines of code.
 Transforms iterative statement into a
formula.
 list comprehension in Python does the
same task and also makes the program
more simple.
 List Comprehensions translate the
traditional iteration approach using for
loop into a simple formula hence making
them easy to use.
 The list comprehensions in Python are
more efficient both computationally and in
terms of coding space and time than a for a
loop. Typically, they are written in a single
line of code.
 Nested List Comprehensions
 Nested List Comprehensions are nothing
but a list comprehension within another list
comprehension which is quite similar to
nested for loops. Below is the program
which implements nested loop.
 We got to know about these things in the
list comprehension.
 How it is used .
 What is the purpose of it.
 How it works.
 Then we got to learn about the Lambda
function in python .
 That how it is used .
 What is the purpose of the lamba function
in python.
 List Comprehensions and Lambda
 Lambda Expressions are nothing but
shorthand representations of Python
functions. Using list comprehensions with
lambda creates an efficient combination.
 A lambda function is a small anonymous
function.
 A lambda function can take any number of
arguments, but can only have one
expression.
 Syntax
 lambda arguments : expression.
 Example
 Add 10 to argument a, and return the
result:
 x = lambda a : a + 10
 print(x(5))
 Example -
 Multiply argument a with argument b and
return the result.
 x = lambda a, b : a * b
 print(x(5, 6)).
 Why Use Lambda Functions?
 The power of lambda is better shown when
one use them as an anonymous function
inside another function.
 Then we got to know and to learn about
the map functions which is used in python.
 We got to learn all about the mapping
function that how and why it is used .
 What is the work of using it.
 What is the syntax of it.
 map() function returns a map object(which
is an iterator) of the results after applying
the given function to each item of a given
iterable (list, tuple etc.)
 Syntax :
 map(fun, iter).
 Parameters :
 fun : It is a function to which map passes
each element of given iterable. iter : It is a
iterable which is to be mapped.
 We, can pass one or more iterable to the
map() function.
 We got to know about the map and the
purpose of mapping in python.
 We got to learn about the different types of
parameters.
 We got to know about the syntax.
 We got to learn about purpose of mapping
in python in depth.
 These are the learning points which I
acquired from the above activites.

Plan for the next week Project ( Pandas and Data Visualization.)
Any leave taken during the week No
Any other point No such other points as of now .

You might also like