Python for Data Science | Oct 17 - Nov 28 | Samriddhi | 2020

Discussion in 'Big Data and Analytics' started by Hitesh H S, Oct 18, 2020.

  1. Hitesh H S

    Hitesh H S Well-Known Member
    Staff Member Simplilearn Support

    Joined:
    May 27, 2020
    Messages:
    131
    Likes Received:
    38
    Hi Learners,

    This thread is for you to discuss the queries and concepts related to the Python for Data Science course only.



    Happy Learning !!

    Regards,
    Team Simplilearn
     
    #1
    I JED FELIX likes this.
  2. Sameer Singh Tuteja

    Joined:
    Sep 19, 2020
    Messages:
    2
    Likes Received:
    0
    Hi Samridhi,
    I think i was not clear with my question on shallow and deep copy. I wanted to talk about nested shallow and deep copy.

    Shallow Copy:
    input :

    a = [1,[2,3],4,5]
    b = a.copy()
    a[2]=9
    a[1][0]=1
    a,b

    Output:
    ([1, [1, 3], 9, 5], [1, [1, 3], 4, 5]) # Here nested elements changes for example a[1][0] impacted b[1][0] but a[2] did not impacted b[2]

    Deep Copy:

    normal_list = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]
    deep_list = copy.deepcopy(normal_list)

    normal_list.append('123')
    normal_list[2][0]= 1
    normal_list[1] = 1

    output: normal_list, deep_list =
    ([[1, 1, 1], 1, [1, 3, 3], '123', '123'], [[1, 1, 1], [2, 2, 2], [3, 3, 3]])


    Hence:
    A shallow copy creates a new object which stores the reference of the original elements.

    So, a shallow copy doesn't create a copy of nested objects, instead it just copies the reference of nested objects. This means, a copy process does not recurse or create copies of nested objects itself.


    A deep copy creates a new object and recursively adds the copies of nested objects present in the original elements.

    The deep copy creates independent copy of original object and all its nested objects.

    Maybe we can discuss this in next class
     
    #2
  3. Sameer Singh Tuteja

    Joined:
    Sep 19, 2020
    Messages:
    2
    Likes Received:
    0
    Another More Simpler Example:

    nl = [1,2,[3,4],5]
    dp = copy.deepcopy(nl) #DeepCopy
    sh = copy.copy(nl) #ShallowCopy

    Command: id(nl),id(dp),id(sh)
    output: (1892157692168, 1892157652424, 1892157667528)


    Command: id(nl[2]),id(dp[2]),id(sh[2])
    Output: (1892157822088, 1892157710664, 1892157822088)


    Command: nl[1]=1000
    nl[2][0]=10

    print(" normal:" , nl,"\n Deep:" ,dp ,"\n Shallow:", sh)

    output: normal: [1, 1000, [10, 4], 5]
    Deep: [1, 2, [3, 4], 5]
    Shallow: [1, 2, [10, 4], 5]
     
    #3
  4. R_3

    R_3 Member

    Joined:
    Sep 5, 2015
    Messages:
    3
    Likes Received:
    0
    Hello, is this the forum which Samridhi asked to upload the solutions for Lists exercises ?
    Thank you
     
    #4
  5. R_3

    R_3 Member

    Joined:
    Sep 5, 2015
    Messages:
    3
    Likes Received:
    0
    @Hitesh
    Hello Hitesh, is this the forum which Samridhi asked to upload the solutions for Lists exercises ?
    Thank you
     
    #5
  6. Support Simplilearn(4685)

    Staff Member Alumni

    Joined:
    Feb 11, 2010
    Messages:
    549
    Likes Received:
    57
    Hello learner,

    This is the forum for all your offline discussions regarding your course (assignments, projects, queries pertaining to the course, etc)

    Hope this helps.
    Happy learning!!
     
    #6
  7. I JED FELIX

    I JED FELIX Member

    Joined:
    Jul 27, 2020
    Messages:
    9
    Likes Received:
    1
    Hello, I am unable to save my python codes as pdf , is there anything I need to do before download as pdf starts working?
    I am using system jupyter notebook.
     
    #7
  8. R_3

    R_3 Member

    Joined:
    Sep 5, 2015
    Messages:
    3
    Likes Received:
    0
    @samridhi: I am Raghava H R. Attached is my attempt for the Lists Exercises.
     

    Attached Files:

    #8
  9. Prasanna K

    Prasanna K Member

    Joined:
    Aug 18, 2020
    Messages:
    3
    Likes Received:
    0
    Hello @samridhi, attached is my attempt for the list exercise.

    Thanks,

    Prasanna
     

    Attached Files:

    #9
  10. Samridhi Dutta

    Samridhi Dutta Well-Known Member
    Alumni Trainer

    Joined:
    Aug 16, 2017
    Messages:
    253
    Likes Received:
    23
    Hi,

    We'll discuss this tomorrow.

    Cheers,
    Samridhi
     
    #10
    UMA SHANKAR_1 likes this.
  11. _84977

    _84977 Member

    Joined:
    Jun 19, 2020
    Messages:
    4
    Likes Received:
    0
    Hello @samridhi, Please find my assignment herewith. Kindly review and share your feedback.
    With Regards,
    Prateek
     

    Attached Files:

    #11
  12. Sweta Naik

    Sweta Naik New Member

    Joined:
    Jun 30, 2020
    Messages:
    1
    Likes Received:
    0
    To print
    IIII
    III​
    II
    I
    Code
    k="I"
    x=' '
    for i in range(4):
    s=4-i
    print("")
    print(i*x,end="")
    for j in range(s):
    print (k,end="");
     
    #12
  13. _76734

    _76734 Member

    Joined:
    Apr 24, 2020
    Messages:
    3
    Likes Received:
    3
    Hello @Samridhi Dutta,

    Please find attached the assignments,

    1. Pattern Assignment
    upload_2020-10-25_17-1-36.png

    2. Dictionary Assignment
    upload_2020-10-25_17-1-0.png
     

    Attached Files:

    #13
    Last edited: Oct 25, 2020
    Arunkumar M and R_3 like this.
  14. _84977

    _84977 Member

    Joined:
    Jun 19, 2020
    Messages:
    4
    Likes Received:
    0
    Hello Samridhi, Please find my submission for today's assignment(Fruit_to_colour) herewith

    fruit_colour = {}
    unique_colour = set(fruit_to_colour.values())
    for colour in unique_colour:
    [Tab]fruit_colour[colour]=[]
    print(fruit_colour)
    for i, (k, v) in enumerate(fruit_to_colour.items()):
    [Tab]fruit_colour[v].append(k)
    print(fruit_colour)
    With Regards,
    Prateek
     
    #14
  15. _79932

    _79932 New Member

    Joined:
    May 24, 2020
    Messages:
    1
    Likes Received:
    0
    Pattern assignment:
    a=0
    for i in range(4,0,-1):
    ch=" "
    print((ch*a)+(i*'1'))
    a=a+1
     
    #15
  16. _77291

    _77291 New Member

    Joined:
    Apr 29, 2020
    Messages:
    1
    Likes Received:
    0
    Hello The the solution for the fruit to colour


    fruit_to_colour = {"watermelon": "green", "pomegranate":"red", "peach": "orange", "cherry": "red", "pear":"green","banana":"yellow", "plum":"purple", "orange": "orange"}
    colour_to_fruit = {}
    for key, value in fruit_to_colour.items():
    if value in colour_to_fruit:
    colour_to_fruit[value].append(key)
    else:
    colour_to_fruit[value]=[key]
    print(colour_to_fruit)
     
    #16
  17. _78880

    _78880 New Member

    Joined:
    May 13, 2020
    Messages:
    1
    Likes Received:
    0
    Hi @Samridhi Dutta ,

    I am not able to find class 3.ipynb in the 17_Oct_Batch folder in google drive. Request you to upload the same.

    Thanks,
    Sreejith
     
    #17
  18. Arunkumar M

    Arunkumar M Member

    Joined:
    Sep 26, 2020
    Messages:
    5
    Likes Received:
    0
    1) Join the elements in the list to represent in date format: dd-mm-YYYY and split it back to represent in the same format for following list: [19, 7, 2019]

    Below is my solution
    lst = [19,7,2019]
    str = f"{lst[0]}-{lst[1]}-{lst[2]}"
    print(str)
    print(str.split("-"))

    output:
    19-7-2019
    ['19', '7', '2019']

    Is this the expected output( solution file doesn't have answer for this question )?
     
    #18
  19. _76734

    _76734 Member

    Joined:
    Apr 24, 2020
    Messages:
    3
    Likes Received:
    3
    Hi @Arunkumar M,

    One suggestion, while your use of f-string is very nice it won't be effective against large lists. Instead you can use str.join() method to join each element of a list with a common separator.

    You can find my attempt below, I took the dd-mm-YYYY part too seriously and did it via datetime.

    upload_2020-10-31_16-56-35.png

     
    #19
    Arunkumar M likes this.
  20. Samridhi Dutta

    Samridhi Dutta Well-Known Member
    Alumni Trainer

    Joined:
    Aug 16, 2017
    Messages:
    253
    Likes Received:
    23
    Hi,

    The file is already there.

    Regards,
    Samridhi
     
    #20
  21. _78415

    _78415 New Member

    Joined:
    May 8, 2020
    Messages:
    1
    Likes Received:
    0
    Hi Samridhi,

    Im getting no output or error while trying out list.count() method
    upload_2020-10-31_19-27-26.png
     
    #21
  22. _76734

    _76734 Member

    Joined:
    Apr 24, 2020
    Messages:
    3
    Likes Received:
    3
    Hi @_78415,

    Don't use "list" as the name of your list directly, it's a reserved keyword thus you can see it's highlighted in green color. Just rename it to list1 or something in both the places and it will work.

     
    #22
  23. _84977

    _84977 Member

    Joined:
    Jun 19, 2020
    Messages:
    4
    Likes Received:
    0
    Hello Samridhi, Could you please explain where itertuples can be used and how to access the content of the tuples.

    I used it on titanic dataframe and I am getting below for list(titanic.itertuples())[0]

    Pandas(Index=1, Survived=0, Pclass=3, Name='Braund, Mr. Owen Harris', Sex='male', Age=22, SibSp=1, Parch=0, Ticket='A/5 21171', Fare=7.25, Cabin='N', Embarked='S', Age_State=3, Fare_Levels=0, IsFemale=0, FamilySize=2, Deck='N', Title='Mr', Age_Cat=1, Name_Upper='BRAUND, MR. OWEN HARRIS', name_l='braund, mr. owen harris', Cap='Braund, mr. owen harris')
     
    #23
  24. kirankumar.j.parmar

    kirankumar.j.parmar New Member

    Joined:
    Oct 21, 2020
    Messages:
    1
    Likes Received:
    0

    Hi
    i have a quary about jupiter notebook , try press ctrl + m but not works plz help m
     
    #24
  25. Arunkumar M

    Arunkumar M Member

    Joined:
    Sep 26, 2020
    Messages:
    5
    Likes Received:
    0
    Hi Samridhi,

    Can you please post the solution file for Pandas_SF Salaries Exercise?

    Question: How many Job Titles were represented by only one person in 2013? (e.g. Job Titles with only one occurence in 2013?)
    Solution: len(sal[sal["Year"] == 2013].JobTitle.unique())

    I am getting the result as 1051 where as the answer posted is 202.
    I double checked the same in excel file & got 1051

    Can you please let me know?

    Thanks
    Arun
     
    #25
  26. Arunkumar M

    Arunkumar M Member

    Joined:
    Sep 26, 2020
    Messages:
    5
    Likes Received:
    0
    Adding to my previous query,

    Question:How many people have the word Chief in their job title?
    Solution: sal.JobTitle.str.contains("Chief").value_counts()[True]

    I got 423 as the output where as the count posted in document is 477

    Please let me know, if I have taken the right approach
     
    #26
  27. Raghavendra B M

    Raghavendra B M Well-Known Member
    Staff Member Simplilearn Support

    Joined:
    Jan 6, 2020
    Messages:
    100
    Likes Received:
    46
    Hi Arunkumar M,

    Please go through the below screenshot you will understand how to solve the problem at hand:
    upload_2020-11-18_10-56-4.png

    I hope that this helped.

    Regards,
    Raghavendra
     
    #27
  28. Arunkumar M

    Arunkumar M Member

    Joined:
    Sep 26, 2020
    Messages:
    5
    Likes Received:
    0
    Thanks Raghavendra.

    For the 2nd Question: How many people have the word Chief in their job title? (This is pretty tricky)

    After running your code, I am getting the output as 627 not 477. Please let me know
     
    #28
  29. Raghavendra B M

    Raghavendra B M Well-Known Member
    Staff Member Simplilearn Support

    Joined:
    Jan 6, 2020
    Messages:
    100
    Likes Received:
    46
    Hi Arunkumar M,

    Please make sure that you have performed the missing value treatment before reaching this step.

    Regards,
    Raghavendra
     
    #29
  30. _84977

    _84977 Member

    Joined:
    Jun 19, 2020
    Messages:
    4
    Likes Received:
    0
    Hi Samridhi,
    For the comcast assignment, could you please clarify what does Q3 mean in the below - Quarter 3 or Question 3 or something else.

    - Provide state wise status of complaints in a stacked bar chart. Use the categorized variable from Q3

    With Regards,
    Prateek
     
    #30
  31. Arunkumar M

    Arunkumar M Member

    Joined:
    Sep 26, 2020
    Messages:
    5
    Likes Received:
    0
    I didn't find any NAN value for that column
    upload_2020-11-22_0-13-4.png
    Please let me know, If I have missed anything
     
    #31
  32. Samridhi Dutta

    Samridhi Dutta Well-Known Member
    Alumni Trainer

    Joined:
    Aug 16, 2017
    Messages:
    253
    Likes Received:
    23
    Hi Arun,

    Uploaded the solutions of this assignment in the same folder. Please refer :)

    Regards,
    Samridhi
     
    #32

Share This Page