Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Name:Aakash Jathore

Roll no: E201


PRN:202301070051

In [5]: import pandas as pd


data = {
'Name': ['rohit','sanket','shridhar','Anushka','nakul'],
'age' : [25,35,26,37,33],
'city': ['pune','mumbai','lonavla','goa','delhi']
}

df = pd.DataFrame(data)
print(df)
print("\n multiple clms")
print(df[['Name','age']])
print("\n filtering rows based age above 20")
print(df[df['age']>20])

# Adding a new column

df['Gender']=['male','male','male','female','male']
print("\n Adding a new column(Gender):")
print(df)

# Dropping a column

df.drop('city',axis=1, inplace=True)
print("\n Dropping a column (city):")
print(df)

#Sorting by values

print("\n Sorting by age in descending order:")


print(df.sort_values(by= 'age', ascending = False))

# Grouping by a column and performing aggregation

print("\nGrouping by gender and calculating average age :")


print(df.groupby('Gender')['age'].mean())

#describe

print(df.describe())

Name age city


0 rohit 25 pune
1 sanket 35 mumbai
2 shridhar 26 lonavla
3 Anushka 37 goa
4 nakul 33 delhi

multiple clms
Name age
0 rohit 25
1 sanket 35
2 shridhar 26
3 Anushka 37
4 nakul 33

filtering rows based age above 20


Name age city
0 rohit 25 pune
1 sanket 35 mumbai
2 shridhar 26 lonavla
3 Anushka 37 goa
4 nakul 33 delhi

Adding a new column(Gender):


Name age city Gender
0 rohit 25 pune male
1 sanket 35 mumbai male
2 shridhar 26 lonavla male
3 Anushka 37 goa female
4 nakul 33 delhi male

Dropping a column (city):


Name age Gender
0 rohit 25 male
1 sanket 35 male
2 shridhar 26 male
3 Anushka 37 female
4 nakul 33 male

Sorting by age in descending order:


Name age Gender
3 Anushka 37 female
1 sanket 35 male
4 nakul 33 male
2 shridhar 26 male
0 rohit 25 male

Grouping by gender and calculating average age :


Gender
female 37.00
male 29.75
Name: age, dtype: float64

In [ ]: !pip install pandas

In [9]: import pandas as pd

df = pd.read_csv('Documents/nike_shoes_sales.csv')
print(df.describe())

print(df)

# What is the average listing price of all products?


average_listing_price = df['listing_price'].mean()
print("1.Average listing price:", average_listing_price)

# 2. How many unique brands are there in the dataset?


unique_brands = df['brand'].unique()
print("2. Number of unique brands:", unique_brands)

# 3. What is the average sale price of all the products?


average_sale_price = df['sale_price'].mean()
print("3.Average sale price:", average_sale_price)

# 4. What is the highest rating given to any product?


highest_rating = df['rating'].max()
print("4. Highest rating:", highest_rating)

# 5.What is the range of listing prices (difference between maximum and minimum)?
listing_price_range = df['listing_price'].max() - df['listing_price'].min()
print("5.Range of listing prices:", listing_price_range)

# 6.How many products have a discount of exactly 0%?


products_with_zero_discount =df[df['discount'] == 0].shape[0]
print("6. Number of products with a discount of 0%:", products_with_zero_discount)

# 7.Which product has the lowest rating?


product_with_lowest_rating = df.loc[df['rating'].idxmin()]['product_name']
print("7. Product with the lowest rating:", product_with_lowest_rating)

# 8.Which brand has the most expensive product?


brand_with_most_expensive_product =df.loc[df['listing_price'].idxmax()]['brand']
print("8. Brand with the most expensive product:", brand_with_most_expensive_product)

# 9.How many Nike products have a discount greater than 10%?


nike_products_discount_gt_10 =df[(df['brand'] == 'Nike') & (df['discount'] > 10)].shape[0]
print("9. Number of Nike products with discount greater than 10%:", nike_products_discount_gt_10)

# 10What is the average rating of Nike products?


average_rating_nike = df[df['brand'] == 'Nike']['rating'].mean()
print("10. Average rating of Nike products:", average_rating_nike)

# 11.Which product has the highest sale price?


product_with_highest_sale_price = df.loc[df['sale_price'].idxmax()]['product_name']
print("11. Product with the highest sale price:", product_with_highest_sale_price)

# 12.How many products have a sale price greater than 0?


products_with_sale_price_gt_0 = df[df['sale_price'] > 0].shape[0]
print("12. Number of products with sale price greater than 0:", products_with_sale_price_gt_0)

# 13.Which product has the highest number of reviews?


product_with_highest_reviews = df.loc[df['reviews'].idxmax()]['product_name']
print("13. Product with the highest number of reviews:", product_with_highest_reviews)

# 14.What is the maximum discount percentage among all products?


max_discount = df['discount'].max()
print("14. Maximum discount percentage:", max_discount)

# 15.What is the median sale price of all products?


median_sale_price = df['sale_price'].median()
print("15. Median sale price:", median_sale_price)

# 16.What is the lowest sale price among all the products?


lowest_sale_price = df['sale_price'].min()
print("16. Lowest sale price:", lowest_sale_price)

# 17.How many products have a rating of 5.0?


products_with_rating_5 = df[df['rating'] == 5.0].shape[0]
print("17. Number of products with a rating of 5.0:", products_with_rating_5)

# 18.How many unique brands are there in the dataset?


unique_brands = df['brand'].nunique()
print("18. Number of unique brands:", unique_brands)

# 19.How many products have a sale price equal to the listing price?
products_with_equal_listing_and_sale_price = df[df['listing_price'] == df['sale_price']].shape[0]
print("19. Number of products with sale price equal to listing price:", products_with_equal_listing_and_sale_price)

# 20. What is the average sale price of all the products?


average_sale_price = df['sale_price'].mean()
print("20.Average sale price:", average_sale_price)

listing_price sale_price discount rating reviews


count 643.000000 643.000000 643.0 643.000000 643.000000
mean 3875.762053 10213.676516 0.0 2.734837 7.181960
std 5889.947172 4513.289512 0.0 2.137756 15.968315
min 0.000000 1595.000000 0.0 0.000000 0.000000
25% 0.000000 6995.000000 0.0 0.000000 0.000000
50% 0.000000 9597.000000 0.0 3.800000 1.000000
75% 8495.000000 12797.000000 0.0 4.600000 6.000000
max 19995.000000 36500.000000 0.0 5.000000 223.000000
product_name product_id listing_price \
0 Nike Air Force 1 '07 Essential CJ1646-600 0
1 Nike Air Force 1 '07 CT4328-101 0
2 Nike Air Force 1 Sage Low LX CI3482-200 0
3 Nike Air Max Dia SE CD0479-200 0
4 Nike Air Max Verona CZ6156-101 0
.. ... ... ...
638 Air Jordan 8 Retro CI1236-100 15995
639 Nike Phantom Venom Club IC AO0578-717 4995
640 Nike Mercurial Superfly 7 Academy TF AT7978-414 8495
641 Nike Air Max 98 AH6799-300 0
642 Nike P-6000 SE CJ9585-600 8995

sale_price discount brand \


0 7495 0 Nike
1 7495 0 Nike
2 9995 0 Nike
3 9995 0 Nike
4 9995 0 Nike
.. ... ... ...
638 12797 0 Nike
639 3497 0 Nike
640 5947 0 Nike
641 16995 0 Nike
642 6297 0 Nike

description rating reviews \


0 Let your shoe game shimmer in the Nike Air For... 0.0 0
1 The legend lives on in the Nike Air Force 1 '0... 0.0 0
2 Taking both height and craft to new levels, th... 0.0 0
3 Designed for a woman's foot, the Nike Air Max ... 0.0 0
4 Pass on the good vibes in the Nike Air Max Ver... 0.0 0
.. ... ... ...
638 The Air Jordan 8 Retro recaptures the memorabl... 5.0 1
639 The Nike Phantom Venom Club IC is engineered f... 0.0 0
640 The soft upper of the Nike Mercurial Superfly ... 5.0 1
641 The Nike Air Max 98 features the OG design lin... 4.0 4
642 A mash-up of Pegasus' past, the Nike P-6000 SE... 0.0 0

images
0 ["https://static.nike.com/a/images/t_PDP_1728_...
1 ["https://static.nike.com/a/images/t_PDP_1728_...
2 ["https://static.nike.com/a/images/t_PDP_1728_...
3 ["https://static.nike.com/a/images/t_PDP_1728_...
4 ["https://static.nike.com/a/images/t_PDP_1728_...
.. ...
638 ["https://static.nike.com/a/images/t_PDP_1728_...
639 NaN
640 NaN
641 ["https://static.nike.com/a/images/t_PDP_1728_...
642 ["https://static.nike.com/a/images/t_PDP_1728_...

[643 rows x 10 columns]


1. Average listing price: 3875.7620528771386
2. Number of unique brands: ['Nike']
3.Average sale price: 10213.676516329704
4. Highest rating: 5.0
5.Range of listing prices: 19995
6. Number of products with a discount of 0%: 643
7. Product with the lowest rating: Nike Air Force 1 '07 Essential
8. Brand with the most expensive product: Nike
9. Number of Nike products with discount greater than 10%: 0
10. Average rating of Nike products: 2.734836702954899
11. Product with the highest sale price: Nike Air VaporMax Flyknit 2 LXX
12. Number of products with sale price greater than 0: 643
13. Product with the highest number of reviews: Air Jordan 10 Retro
14. Maximum discount percentage: 0
15. Median sale price: 9597.0
16. Lowest sale price: 1595
17. Number of products with a rating of 5.0: 120
18. Number of unique brands: 1
19. Number of products with sale price equal to listing price: 0
20.Average sale price: 10213.676516329704
In [ ]:

In [ ]:

You might also like