Welcome to the Simplilearn Community

Want to join the rest of our members? Sign up right away!

Sign Up

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

Hitesh H S

Well-Known Member
Staff member
Simplilearn Support
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
 
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
 
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]
 

R_3

Member
Hello, is this the forum which Samridhi asked to upload the solutions for Lists exercises ?
Thank you
 

R_3

Member
@Hitesh
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

Hello Hitesh, is this the forum which Samridhi asked to upload the solutions for Lists exercises ?
Thank you
 

Support Simplilearn(4685)

Moderator
Staff member
Alumni
Hello, is this the forum which Samridhi asked to upload the solutions for Lists exercises ?
Thank you

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!!
 
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.
 

Samridhi Dutta

Well-Known Member
Alumni
Trainer
Hi,

We'll discuss this tomorrow.

Cheers,
Samridhi
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]
 

_84977

Member
Hello @samridhi, Please find my assignment herewith. Kindly review and share your feedback.
With Regards,
Prateek
 

Attachments

  • 1. Lists_Exercises_Prateek.ipynb.zip
    913 bytes · Views: 3
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="");
 

_84977

Member
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
 

_77291

New Member
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)
 
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 )?
 

_76734

Member
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

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 )?
 

_84977

Member
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')
 
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
 
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
 

Raghavendra B M

Moderator
Staff member
Simplilearn Support
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

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
 

Raghavendra B M

Moderator
Staff member
Simplilearn Support
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

Hi Arunkumar M,

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

Regards,
Raghavendra
 

_84977

Member
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
 

Samridhi Dutta

Well-Known Member
Alumni
Trainer
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

Hi Arun,

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

Regards,
Samridhi
 
I have a question for assignment titled "App Rating Prediction", where there are more than 1695 of 9360 entries that have "varies with Devic" value. What do we do with them? Delete all those rows? Will that skew data. I can't convert them to numeric like we do for those with suffix M or K
 
I dont understand what I should do here. it is not clear.

6. Outlier treatment:

  1. Price: From the box plot, it seems like there are some apps with very high price. A price of $200 for an application on the Play Store is very high and suspicious!
    1. Check out the records with very high price
      1. Is 200 indeed a high price?
    2. Drop these as most seem to be junk apps
  2. Reviews: Very few apps have very high number of reviews. These are all star apps that don’t help with the analysis and, in fact, will skew it. Drop records having more than 2 million reviews.
  3. Installs: There seems to be some outliers in this field too. Apps having very high number of installs should be dropped from the analysis.
    1. Find out the different percentiles – 10, 25, 50, 70, 90, 95, 99
    2. Decide a threshold as cutoff for outlier and drop records having values more than that
 
Top