Welcome to the Simplilearn Community

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

Sign Up

DS with Python | Dec 14 - Jan 15 (2020-21) | Wajahat

Hi Sir,
Please find the assignment

import numpy as np


countries = np.array(['Algeria','Angola','Argentina','Australia','Austria','Bahamas','Bangladesh','Belarus','Belgium','Bhutan','Brazil','Bulgaria','Cambodia','Cameroon','Chile','China','Colombia','Cyprus','Denmark','El Salvador','Estonia','Ethiopia','Fiji','Finland','France','Georgia','Ghana','Grenada','Guinea','Haiti','Honduras','Hungary','India','Indonesia','Ireland','Italy','Japan','Kenya', 'South Korea','Liberia','Malaysia','Mexico', 'Morocco','Nepal','New Zealand','Norway','Pakistan', 'Peru','Qatar','Russia','Singapore','South Africa','Spain','Sweden','Switzerland','Thailand', 'United Arab Emirates','United Kingdom','United States','Uruguay','Venezuela','Vietnam','Zimbabwe'])

gdp_per_capita = np.array([2255.225482,629.9553062,11601.63022,25306.82494,27266.40335,19466.99052,588.3691778,2890.345675,24733.62696,1445.760002,4803.398244,2618.876037,590.4521124,665.7982328,7122.938458,2639.54156,3362.4656,15378.16704,30860.12808,2579.115607,6525.541272,229.6769525,2242.689259,27570.4852,23016.84778,1334.646773,402.6953275,6047.200797,394.1156638,385.5793827,1414.072488,5745.981529,837.7464011,1206.991065,27715.52837,18937.24998,39578.07441,478.2194906,16684.21278,279.2204061,5345.213415,6288.25324,1908.304416,274.8728621,14646.42094,40034.85063,672.1547506,3359.517402,36152.66676,3054.727742,33529.83052,3825.093781,15428.32098,33630.24604,39170.41371,2699.123242,21058.43643,28272.40661,37691.02733,9581.05659,5671.912202,757.4009286,347.7456605])

max_gdp_per_capita=gdp_per_capita.argmax()

Countries_max_gdp_per_capita=countries[max_gdp_per_capita]

min_gdp_per_capita=gdp_per_capita.argmin()

countries_min_gdp_per_capita=countries[min_gdp_per_capita]


#Name of the country with Maximum GDP

Countries_max_gdp_per_capita


#Name of the country with Minimum GDP

countries_min_gdp_per_capita


for country in countries:

print('Calculating country {}'.format(country))


#Print entire list of countries and their GDP

for i in range(len(countries)):

country = countries

country_gdp_per_capita=gdp_per_capita

print('Country {} per capita gdp is {}'.format(country,country_gdp_per_capita))


print(gdp_per_capita.max())

print(gdp_per_capita.min())

print(gdp_per_capita.mean())

print(gdp_per_capita.std())

print(gdp_per_capita.sum())
 

mdwajtech

Well-Known Member
Hi ,
I have uploaded couple of questions for practice in the google drive.
Will upload few more assignments in next couple of days

Thanks
 

Abhinav Ranjan

Member
Alumni
Hi,

Please find the assignment for banking scenario/use case:




employee_data = {
'employee 1':
{'employee id' : 123,
'employee password' : '123password',
'Name' : 'Sara',
'Address' : '123J/111A',
'Phone Number' : '123456789',
'balance' : 30000,
'Last Withdrawal Amount' : 10000,
'Last Deposit Amount' : 20000,
'Last Withdrawal Date' : '28/11/2020',
'Last Deposit Date' : '20/10/2020'
},
'employee 2' :
{'employee id' : 124,
'employee password' : '124password',
'Name' : 'Jack',
'Address' : '123J/112B',
'Phone Number' : '987654321',
'balance' : 30000,
'Last Withdrawal Amount' : 10000,
'Last Deposit Amount' : 20000,
'Last Withdrawal Date' : '28/11/2020',
'Last Deposit Date' : '20/10/2020'
},
}


employee_id = int(input('Enter your employee_id: '))
password = input('Enter your password: ')

employee_data_keys = list(employee_data.keys())

for i in range(0, len(employee_data.keys())):
if employee_id == employee_data[employee_data_keys]['employee id'] and password == employee_data[employee_data_keys]['employee password']:
try:
update_type = int(input('Please choose from below option:\n 1. Address\n 2. Phone Number\n 3. Withdrawal\n 4. Deposit\n\n '))
if update_type == 1:
employee_data[employee_data_keys]['Address'] = input('Please enter the address to update: ')
print('\n Address Updated Succesfully\n')
elif update_type == 2:
employee_data[employee_data_keys]['Phone Number'] = input('Please enter the phone number to update: ')
print('\n Phone Number Updated Succesfully\n')
elif update_type == 3:
withdrawl_amount = int(input('Please enter the Withdrawl amount: '))
if employee_data[employee_data_keys]['balance'] > withdrawl_amount:
balance = employee_data[employee_data_keys]['balance'] = employee_data[employee_data_keys]['balance'] - withdrawl_amount
employee_data[employee_data_keys]['Last Withdrawal Amount'] = withdrawl_amount
employee_data[employee_data_keys]['balance'] = balance
print('\n Your transaction was succesfull. Remaining balance in your account is: Rs. ', balance, 'Thank you for using our bank, have a nice day....\n')
else:
print("\nSorry you don't have sufficient amount to withdraw\n")
break
elif update_type == 4:
deposit_amount = int(input('Please enter the deposit amount: '))
balance = employee_data[employee_data_keys]['balance']+deposit_amount
employee_data[employee_data_keys]['balance'] = balance
employee_data[employee_data_keys]['Last Deposit Amount'] = employee_data[employee_data_keys]['balance']+deposit_amount
print('\nYour transaction was succesfull. Balance in your account is: Rs. ', balance, '\n')
print(employee_data)
break
except:
print('Wrong input please input from 1-4')
else:
print('\nEmployee id or password does not matches\n')
 

Attachments

  • assignment_19-12-20.pdf
    936.1 KB · Views: 2

Ross M Ilardi

New Member
Attached are the 2 assignments:
1.) Analyze GDP of Countries
2.) Create Banking Function

Unable to add the below Code:
a. check to ensure the Employee password is associated the correct Employee id
b. perform update to dictionary for Address, Phone #, Balance
c. show last Withdrawal and Deposit amounts and update dates for each transaction
 

Attachments

  • Analyze_GDP_Countries.txt
    3.5 KB · Views: 5
  • Banking_Function.txt
    4.5 KB · Views: 2
Last edited:
Hello Sir,

This is My GDP Code

import numpy as np

countries = np.array(['Algeria','Angola','Argentina','Australia','Austria','Bahamas','Bangladesh','Belarus',
'Belgium','Bhutan','Brazil','Bulgaria','Cambodia','Cameroon','Chile','China','Colombia','Cyprus',
'Denmark','El Salvador','Estonia','Ethiopia','Fiji','Finland','France','Georgia','Ghana','Grenada',
'Guinea','Haiti','Honduras','Hungary','India','Indonesia','Ireland','Italy','Japan','Kenya',
'South Korea','Liberia','Malaysia','Mexico', 'Morocco','Nepal','New Zealand','Norway','Pakistan',
'Peru','Qatar','Russia','Singapore','South Africa','Spain','Sweden','Switzerland','Thailand',
'United Arab Emirates','United Kingdom','United States','Uruguay','Venezuela','Vietnam','Zimbabwe'])

len(countries)

gdp = np.array([2255.225482,629.9553062,11601.63022,25306.82494,27266.40335,19466.99052,588.3691778,2890.345675,
24733.62696,1445.760002,4803.398244,2618.876037,590.4521124,665.7982328,7122.938458,2639.54156,3362.4656,
15378.16704,30860.12808,2579.115607,6525.541272,229.6769525,2242.689259,27570.4852,23016.84778,1334.646773,
402.6953275,6047.200797,394.1156638,385.5793827,1414.072488,5745.981529,837.7464011,1206.991065,27715.52837,
18937.24998,39578.07441,478.2194906,16684.21278,279.2204061,5345.213415,6288.25324,1908.304416,274.8728621,
14646.42094,40034.85063,672.1547506,3359.517402,36152.66676,3054.727742,33529.83052,3825.093781,15428.32098,
33630.24604,39170.41371,2699.123242,21058.43643,28272.40661,37691.02733,9581.05659,5671.912202,757.4009286,347.7456605])

len(gdp)

# Find and Print the name of the country with the highest GDP
print("Highest GDP for country is:",countries[gdp.argmax()])

# Find and Print the name of the country with the lowest GDP
print("Lowest GDP for country is:",countries[gdp.argmin()])

# Print out text and input values iteratively
for country in countries:
print(country)
for gdps in gdp:
print(gdps)

# Print out the entire list of the countries with their GDPs
print("Country","GDP")
print("==================")
for i in range(gdp.size):
print(countries,"=",gdp)

# Highest GDP value
print("Highest GDP Value:",gdp[gdp.argmax()])
# Lowest GDP value
print("Lowest GDP Value:",gdp[gdp.argmin()])
# Mean GDP value
print("Mean GDP Value:",gdp.mean())
# Standardized GDP value
print("Standardized GDP Value:",gdp.std())
# Sum of all GDP values
print("Sum of GDP Values:",gdp.sum())
 
Hi Md. Wajahat,

Please find the attached assignment for

Chapter - 5
- GDP Assignment
- Olympic Assignment
Chapter - 6
- Linear Algebra Assignment
- CDF and PDF Assignment
Chapter - 7
- Federal Aviation Authority Assignment
- NewYork city fire department Assignment

Please review and advise.

Regards,

Shailendra
 

Attachments

  • Assignment on GDP of countries - Python Code & screen shots by Shailendra Srivastava.pdf
    460 KB · Views: 4
  • Code and Screen shot Olympic with numpy only by Shailendra .pdf
    300.9 KB · Views: 1
  • Code and Screen shot Olympic with pandas by Shailendra.pdf
    367.3 KB · Views: 1
  • Linear Algebra assignment of Chapter 6 - Code & Screen Shot by Shailendra Srivastava.pdf
    132.7 KB · Views: 1
  • CDF and PDF-Scipy assignment of Chapter 6 - Code & Screen Shot by Shailendra Srivastava.pdf
    123.8 KB · Views: 1
  • Federal Aviation Authority Assignment Chapter 7 -Code & Screen Shot by Shailendra Srivastava.pdf
    472.4 KB · Views: 6
  • NewYork city fire department Assignment of Chapter 7 - Code & Screen Shot by Shailendra.pdf
    459 KB · Views: 6
In movielens project, I am getting an error while merging the table using MovieID and UserID. Please see below:

dataframe_master_data = pd.merge(dataframe_movies_and_ratings, dataframe_users, on = ['UserID'])
dataframe_master_data.head()

KeyError Traceback (most recent call last)
<ipython-input-8-10c5a101aba2> in <module>
----> 1dataframe_master_data = pd.merge(dataframe_movies_and_ratings, dataframe_users, on = ['UserID'])
2 dataframe_master_data.head()

~\anaconda3\lib\site-packages\pandas\core\reshape\merge.py in merge(left, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy, indicator, validate)
72 validate=None,
73 ) -> "DataFrame":
---> 74 op = _MergeOperation(
75 left,
76 right,

~\anaconda3\lib\site-packages\pandas\core\reshape\merge.py in __init__(self, left, right, how, on, left_on, right_on, axis, left_index, right_index, sort, suffixes, copy, indicator, validate)
650 self.right_join_keys,
651 self.join_names,
--> 652 ) = self._get_merge_keys()
653
654 # validate the merge keys dtypes. We may need to coerce

~\anaconda3\lib\site-packages\pandas\core\reshape\merge.py in _get_merge_keys(self)
1003 if not is_rkey(rk):
1004 if rk is not None:
-> 1005right_keys.append(right._get_label_or_level_values(rk))
1006 else:
1007 # work-around for merge_asof(right_index=True)

~\anaconda3\lib\site-packages\pandas\core\generic.py in _get_label_or_level_values(self, key, axis)
1561 values = self.axes[axis].get_level_values(key)._values
1562 else:
-> 1563raise KeyError(key)
1564
1565 # Check for duplicates

KeyError: 'UserID'


In [ ]:
 

Ravi kumar_48

Customer
Customer
has anyone completed the pending tasks in project2?
3. Top 25 movies by viewership rating
4. Find the ratings for all the movies reviewed by for a particular user of user id = 2696
 

Ravi kumar_48

Customer
Customer
has anyone completed the pending tasks in project2?

below are my answer, could someone confirm me is it okay?
3. Top 25 movies by viewership rating
viewership_rating = master_data[['Title','Rating']]
viewership_rating.sort_values(by=['Rating'])
df = viewership_rating.drop_duplicates(subset=['Title'])
Top_25_movies_Title = df.head(25)
Top_25_movies_Title

4. Find the ratings for all the movies reviewed by for a particular user of user id = 2696
master_data[master_data.UserID == 2696][['Title','Rating']]
 
Hi,

I am doing project need help on how to use ax.annotate with below command.

dfcomcast.groupby(pd.Grouper(freq="M")).size().plot( ), plt.title('Comcast Telecom Complaints Monthwise')
plt.xlabel("Month")
plt.ylabel("No Of Complaint")

123.png
 
I got unique genre & after that tried to check if the unique genre is present in genre & uuppdate accordingly. Buut the code is hanging. can you help. It does not give any error message but no output as well. Tried restarting kernel as well multiple times

df_merge_genre=df_merge
for i in Genre_unique:
for j in df_merge_genre.index:
if i in df_merge_genre.iloc[j].Genre:
df_merge_genre.at[j,i]=1
else:
df_merge_genre.at[j,i]=0
df_merge_genre.head(25)
 
Top