Python Data Science Jobs & Interviews
20.4K subscribers
188 photos
4 videos
25 files
326 links
Your go-to hub for Python and Data Science—featuring questions, answers, quizzes, and interview tips to sharpen your skills and boost your career in the data-driven world.

Admin: @Hussein_Sheikho
Download Telegram
1. What is the primary data structure in pandas?
2. How do you create a DataFrame from a dictionary?
3. Which method is used to read a CSV file in pandas?
4. What does the head() function do in pandas?
5. How can you check the data types of columns in a DataFrame?
6. Which function drops rows with missing values in pandas?
7. What is the purpose of the merge() function in pandas?
8. How do you filter rows based on a condition in pandas?
9. What does the groupby() method do?
10. How can you sort a DataFrame by a specific column?
11. Which method is used to rename columns in pandas?
12. What is the difference between loc and iloc in pandas?
13. How do you handle duplicate rows in pandas?
14. What function converts a column to datetime format?
15. How do you apply a custom function to a DataFrame?
16. What is the use of the apply() method in pandas?
17. How can you concatenate two DataFrames?
18. What does the pivot_table() function do?
19. How do you calculate summary statistics in pandas?
20. Which method is used to export a DataFrame to a CSV file?

#️⃣ #pandas #dataanalysis #python #dataframe #coding #programming #datascience

By: t.iss.one/DataScienceQ 🚀
#pandas #python #programming #question #dataframe #intermediate

Write a Python program using pandas to perform the following tasks:

1. Create a DataFrame from a dictionary with columns: 'Product', 'Category', 'Price', and 'Quantity' containing:
- Product: ['Laptop', 'Mouse', 'Keyboard', 'Monitor', 'Headphones']
- Category: ['Electronics', 'Accessories', 'Accessories', 'Electronics', 'Accessories']
- Price: [1200, 25, 80, 300, 100]
- Quantity: [10, 50, 30, 20, 40]

2. Add a new column 'Total_Value' that is the product of 'Price' and 'Quantity'.

3. Calculate the total value for each category and print it.

4. Find the product with the highest total value and print its details.

5. Filter the DataFrame to show only products in the 'Electronics' category with a price greater than 200.

import pandas as pd

# 1. Create the DataFrame
data = {
'Product': ['Laptop', 'Mouse', 'Keyboard', 'Monitor', 'Headphones'],
'Category': ['Electronics', 'Accessories', 'Accessories', 'Electronics', 'Accessories'],
'Price': [1200, 25, 80, 300, 100],
'Quantity': [10, 50, 30, 20, 40]
}
df = pd.DataFrame(data)

# 2. Add Total_Value column
df['Total_Value'] = df['Price'] * df['Quantity']

# 3. Calculate total value by category
total_by_category = df.groupby('Category')['Total_Value'].sum()

# 4. Find product with highest total value
highest_value_product = df.loc[df['Total_Value'].idxmax()]

# 5. Filter electronics with price > 200
electronics_high_price = df[(df['Category'] == 'Electronics') & (df['Price'] > 200)]

# Print results
print("Original DataFrame:")
print(df)
print("\nTotal Value by Category:")
print(total_by_category)
print("\nProduct with Highest Total Value:")
print(highest_value_product)
print("\nElectronics Products with Price > 200:")
print(electronics_high_price)

Output:
Original DataFrame:
Product Category Price Quantity Total_Value
0 Laptop Electronics 1200 10 12000
1 Mouse Accessories 25 50 1250
2 Keyboard Accessories 80 30 2400
3 Monitor Electronics 300 20 6000
4 Headphones Accessories 100 40 4000

Total Value by Category:
Category
Accessories 7650
Electronics 18000
dtype: int64

Product with Highest Total Value:
Product Laptop
Category Electronics
Price 1200
Quantity 10
Total_Value 12000
Name: 0, dtype: object

Electronics Products with Price > 200:
Product Category Price Quantity Total_Value
0 Laptop Electronics 1200 10 12000

By: @DataScienceQ 🚀