Amazon Python Interview Question for a Data Engineer L4 Position | Python For Data Analytics
HTML-код
- Опубликовано: 25 янв 2024
- In this video we are going to discuss a Python Interview problem asked in Amazon for a data engineer Position.
Here is the input list:
emp_list=[('Ankit',10000),('Rahul',12000),('Sumit',14000),('Dheeraj',21000),('Pavan',11000),('Mohit',13000)]
Expected Output: [('Sumit',14000),('Dheeraj',21000)]
Zero to hero(Advance) SQL Aggregation:
• All About SQL Aggregat...
Most Asked Join Based Interview Question:
• Most Asked SQL JOIN ba...
Solving 4 Trick SQL problems:
• Solving 4 Tricky SQL P...
Data Analyst Spotify Case Study:
• Data Analyst Spotify C...
Top 10 SQL interview Questions:
• Top 10 SQL interview Q...
Interview Question based on FULL OUTER JOIN:
• SQL Interview Question...
Playlist to master SQL :
• Complex SQL Questions ...
Rank, Dense_Rank and Row_Number:
• RANK, DENSE_RANK, ROW_...
#python #dataengineer
Thank you so much Ankit for making video on data validation using Python 🙏🏻❤
My pleasure😊
Do give a thumbs up to the video for more Python Interview Questions😊
Kindly continue this python series Ankit... Kind request from one of your fan.. ❤❤❤
To show off python skills:
avg = sum(emp[1] for emp in emp_list)/len(emp_list)
result= list(filter
(lambda x: x[1]>avg, emp_list))
print(result)
avg_salary=sum(i[1]for i in emp_list)/len(emp_list)
print([i for i in emp_list if i[1]>avg_salary])
Please continue posting similar python videos as well👍👍
Thank you Ankit for making such practical videos on Python 🙏🙏🙏
Eagerly waiting for more such videos!!
Sir Today I saw your first video, how easily you explained every concept, thank you so much sir :)
DSA for the Data Engineer / Data Analyst or Data Science ROle :
ruclips.net/p/PLqGLh1jt697wQTamFvXx_Odlm-Wg3zbxq&si=6owKBIz4xO93BxPN
I reallly needed this series sir, THANKYOU
we want more python videos ankit , keep em coming
100 percent 😊
Thanks @ankit looking forward to more such examples.
Your sql videos have helped us a lot in our career. Please make more videos in python as well:)
Thanks Ankit for Python🐍 Content as well. Needed the most 🍀
Great initiative 💯
This will help us a lot, thankyou so much 🙏
My pleasure 😊
We need more videos on python question . Thanks!
Very informative , very much demanding video, bro please bring everyday it's very helpful...❤❤❤
Thank you, I will
import numpy as np
avg_sal = np.mean([x[1] for x in emp_list])
print([x for x in emp_list if x[1] > avg_sal])
This is much better since numpy is more efficient due to vectorization
Alternative solution using pandas
emp_list = [('Ankit', 10000), ('Rahul', 12000), ('Sumit', 14000), ('Dheeraj', 21000), ('Pavan', 11000), ('Mohit', 13000)]
df = pd.DataFrame(emp_list, columns=['emp_name', 'Salary'])
average_salary = df['Salary'].mean()
df[df['Salary'] > average_salary]
Thanks Ankit..❤ please start python interview question series
its a good video ankit
def avg_sal(emp_list):
avg_sal = sum(i[1] for i in emp_list)/ len(emp_list)
return [x for x in emp_list if x[1] > avg_sal]
This is nice..👍👍
Man What a Head you Have Ankit genius😁🙌👌
Python series would be great Ankit...
Please can you upload video on implementation of statistical concept using python
Now i can solve complex sql question after doing your sql video series, but I am missing python, Please do python interview question, thank you sir for your effort and time
@ankit bansal it is a great way to learn basics
We want more video like this. If may I request, you can type in notebook comments the python concept used to solve probelm. Like in this problem concept used is tuple unpacking..
Thank you, its really helpfull.
You're welcome!
Created a dataframe and stored the value of the list and then using the pandas dataframe manipulation to filter the names of the employees salary greater than average.
How can we append multiple dictionaries with same key but different values in empty list of dictionary dynamically
My Solution:
emp_list=[('Ankit',10000),('Rahul',12000),('Sumit',14000),('Dheeraj',21000),('Pavan',11000),('Mohit',13000)]
avg_sal = sum([second for first,second in emp_list])/len(emp_list)
print([emp for emp in emp_list if emp[1] > avg_sal])
This is so easy
Please do more videos 🙏
Thanks for explaining but you should have covered list comprehension in the same video as well so that everyone will get all the flavor
Sol :
import numpy as np
final_list = [val for val in emp_list if val[1] > np.mean([val[1] for val in emp_list])]
Good point.
avg_sal=((sum([i[1] for i in emp_list]))/len(emp_list))
print([i for i in emp_list if i[1]>=avg_sal])
emp_name= [tuple[0] for tuple in emp_list if tuple[1]>=np.mean([val[1] for val in emp_list])]
Convert the data into data frame
Df=pd.dataframe(data)
df['avg'] = df['salary'].mean()
filtered_df = df[df['salary'] > df['avg']]
I think Pandas are not allowed by interviewer
Plz do more python plz plz
why do we use python when we have SQL? I have mainly used pandas just for pivot tables, since making a pivot table in sql is not that convenient. Most of them time when I am working with a df in a jupyter notebook instead of a table in a database I just google how to do this in python the way I would have done it in sql. Okay of course if you need to connect to an api and scrape a bit, it is useful but besides that why do we need it for simple filtering?
Bro please start AWS training
emp_list = [('Ankit', 10000), ('Rahul', 12000), ('Sumit', 14000), ('Dheeraj', 21000), ('Pavan', 11000), ('Mohit', 13000)]
total_salary=0
for name,salary in emp_list:
total_salary+=salary
avg=total_salary/len(emp_list)
print(avg)
print([(name,salary) for name, salary in emp_list if salary > avg])
My solution:
▪List comprehension to extract salaries.
emp_salary = [salary for name, salary in emp_list]
▪Calculate average salary
avg_salary = sum(emp_salary) / len(emp_salary)
▪List comprehension to filter employees whose salary is greater than the average salary
expected = [(name, salary) for name, salary in emp_list if salary > avg_salary]
▪print(expected)
[('Sumit', 14000), ('Dheeraj', 21000)]
data=[ ('Ankit',10000),('Rahul',12000),('Sumit',14000),('Dheraj',21000),('Pavan',11000),('Mohit',13000)]
print(data)
avg_sal=sum(sal for _, sal in data)/len(data)
output=[i for i in data if i[-1]>avg_sal]
print(output)
Sir when you are going to again start SQL course
March
this is normal lite life, use list comprehensions for mentos pro max
Sure
can you please start a dedicated bootcamp on this please
It's already going on
@@ankitbansal6 Pls send link to register
Isn't this too easy for Amazon.
How can we do this looping once
It's for L4 position. So its fine.
def final_required_output_calc(emp_list):
sum_of_salary=0
for i in range(len(emp_list)):
sum_of_salary=sum_of_salary+emp_list[i][1]
average_salary=sum_of_salary/len(emp_list)
final_list=[]
for i in range(len(emp_list)):
if emp_list[i][1]>average_salary:
final_list.append(emp_list[i])
return final_list
Edit:Saw your solution it is almost same 😂
using list comprehension:
emp_list = [('Ankit', 10000), ('Rahul', 12000), ('Sumit', 14000), ('Dheeraj', 21000), ('Pavan', 11000), ('Mohit', 13000)]
avg_sal = sum(salary for name, salary in emp_list) / len(emp_list)
my_list = [(name, salary) for name, salary in emp_list if salary > avg_sal]
print(my_list)
emp_list = [('Ankit', 10000), ('Rahul', 12000), ('Sumit', 14000), ('Dheeraj', 21000), ('Pavan', 11000),
('Mohit', 13000)]
emp_dict = dict(emp_list)
avg = sum(emp_dict.values()) / len(emp_dict)
print(f"average salary:{avg}")
employee_avg_list = [(key, value) for key, value in emp_dict.items() if value > avg]
print(employee_avg_list)
my code
def get_avg_sal(tup_list):
total = sum(sal for _, sal in tup_list) # Calculate the total salary using a generator expression
return total / len(tup_list)
def get_name(tup_list, avg_sal):
return [(name, sal) for name, sal in tup_list if sal > avg_sal]
avg_sal = get_avg_sal(tup_list)
my_list = get_name(tup_list, avg_sal)
print(my_list)